﻿using DX_Recognize.AuxiliaryTool;
using DX_Recognize.Common;
using DX_Recognize.Entitys;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Data;
using System.Drawing.Design;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Windows.Input;
using ZWCAD;
using ZwSoft.ZwCAD.ApplicationServices;
using ZwSoft.ZwCAD.Colors;
using ZwSoft.ZwCAD.DatabaseServices;
using ZwSoft.ZwCAD.DatabaseServices.Filters;
using ZwSoft.ZwCAD.EditorInput;
using ZwSoft.ZwCAD.Geometry;
using ZwSoft.ZwCAD.GraphicsInterface;
using ZwSoft.ZwCAD.Windows;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Header;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
using Application = ZwSoft.ZwCAD.ApplicationServices.Application;
using Polyline = ZwSoft.ZwCAD.DatabaseServices.Polyline;

namespace DX_Recognize.Utils
{
    public class RecognizeUtils
    {
        //客图正视图 投影图 是否都带中心线
        static public Boolean AVCF = false;
        static public string CustomerNum = null;
        static public DataForm dataForm = new DataForm();
        static public ComputedUtils CU = new ComputedUtils();
        static public PictureFrameCondiInfo TopViewPicCondiInfo = new PictureFrameCondiInfo();
        static public PictureFrameCondiInfo AssemblyViewPicCondiInfo = new PictureFrameCondiInfo();
        public static RCBoardBeCall NCUIBoardDataEvent;
        public static RCItemBeCall NCUIItemDataEvent;
        public static RCSItemBeCall NCUISItemDataEvent;
        public static ShowMenuCall NotityMenuShowEvent;
        public static SetModeNumCall SetModeNumEvent;
        public static TopViewInfoData WholeTopViewData = new TopViewInfoData();
        public RecognizeUtils()
        {
            //Register
            NCUIBoardDataEvent += dataForm.AutoPageRenderBoardUIData;
            NCUIItemDataEvent += dataForm.RenderItemUIData;
            NCUISItemDataEvent += dataForm.SurplusItemDrivenRenderUI;
            NotityMenuShowEvent += dataForm.MenuShow;
            SetModeNumEvent += dataForm.SetModeNumberValue;
        }

        public async void showForm()
        {
            Application.ShowModelessDialog(dataForm);
        }

        //Auto Type Re Render UI
        public static void AutoTypeCRUIAfterRecognizeEvent(RenderType RT)
        {
            if (NCUIBoardDataEvent != null)
                NCUIBoardDataEvent(RT);
            NCUIItemDataEvent();
            NCUISItemDataEvent(ShareItemData.UISurplusItemList);
        }

        public static void CallMenuShow()
        {
            if (NotityMenuShowEvent != null)
                NotityMenuShowEvent();
        }

        public static void CallSetModeNum(string ModeNum)
        {
            if (SetModeNumEvent != null)
                SetModeNumEvent(ModeNum);
        }

        public static void SetCADDWGAssemblyPlaneData(ObjectId objectId, List<Polyline> APolyLineList,AssemViewCADInfo AVInfo, Entity entity)
        {
            if (entity is RotatedDimension dim)
            {
                CAD_Dimension Item = new CAD_Dimension();
                double Y1 = dim.XLine1Point.Y;
                double Y2 = dim.XLine2Point.Y;
                double highY = Y1 > Y2 ? Y1 : Y2;
                double lowY = Y1 < Y2 ? Y1 : Y2;
                Item.HighY = highY;
                Item.LowY = lowY;
                Item.DimensionLength = Math.Round((double)Item.HighY - (double)Item.LowY, 1);
                Item.X = dim.XLine1Point.X;
                AVInfo.ADimList.Add(Item);
            }
            if (entity is DBText text)
            {
                MixedCAD_Text Item = new MixedCAD_Text();
                Item.PositionPoint = new MixedCAD_Point();
                double X = Math.Round(text.Position.X, 3);
                double Y = Math.Round(text.Position.Y, 3);
                double Z = Math.Round(text.Position.Z, 3);
                Item.Centent = text.TextString;
                AVInfo.ATextList.Add(Item);
            }
            if (entity is MText mtext)
            {
                string textContent = mtext.Text;
                double X = Math.Round(mtext.Location.X, 3);
                double Y = Math.Round(mtext.Location.Y, 3);
                double Z = Math.Round(mtext.Location.Z, 3);
                string[] MTextList = textContent.Split(new string[] { "\r\n" }, StringSplitOptions.None);
                for (int i = 0; i < MTextList.Length; i++)
                {
                    MixedCAD_Text Item = new MixedCAD_Text();
                    Item.PositionPoint = new MixedCAD_Point();
                    Item.PositionPoint.CustomerPoint.X = X;
                    Item.PositionPoint.CustomerPoint.Y = Y;
                    Item.PositionPoint.CustomerPoint.Z = Z;
                    Item.Centent = MTextList[i];
                    AVInfo.ATextList.Add(Item);
                }
            }
            if (entity is Polyline polyline)
                APolyLineList.Add(polyline);
            if (entity is Line line)
            {
                if (line.Linetype.Contains("CENTER") || line.Linetype == "EB_DASHDOT")
                //if (line.Linetype.Contains("CENTER"))
                {
                    MixedCAD_Line temp = new MixedCAD_Line();
                    temp.StartPoint.CustomerPoint.X = line.StartPoint.X;
                    temp.StartPoint.CustomerPoint.Y = line.StartPoint.Y;
                    temp.EndPoint.CustomerPoint.X = line.EndPoint.X;
                    temp.EndPoint.CustomerPoint.Y = line.EndPoint.Y;
                    temp.Length = line.Length;
                    temp.LayerName = line.Layer;
                    temp.ColorInfo.ColorIndex = line.ColorIndex.ToString();
                    temp.ColorInfo.ColorNameForDisplay = line.Color.ColorNameForDisplay;
                    temp = TransCADItemLineData(temp);
                    AVInfo.ACLList.Add(temp);
                }
                else
                {
                    MixedCAD_Line temp = new MixedCAD_Line();
                    temp.StartPoint.CustomerPoint.X = line.StartPoint.X;
                    temp.StartPoint.CustomerPoint.Y = line.StartPoint.Y;
                    temp.EndPoint.CustomerPoint.X = line.EndPoint.X;
                    temp.EndPoint.CustomerPoint.Y = line.EndPoint.Y;
                    temp.Length = line.Length;
                    temp.LayerName = line.Layer;
                    temp.ColorInfo.ColorIndex = line.ColorIndex.ToString();
                    temp.ColorInfo.ColorNameForDisplay = line.Color.ColorNameForDisplay;
                    temp = TransCADItemLineData(temp);
                    AVInfo.AVLList.Add(temp);
                }
            }

            if (entity is Circle circle)
            {
                MixedCAD_Circle temp = new MixedCAD_Circle();
                temp.CenterPoint.CustomerPoint.X = circle.Center.X;
                temp.CenterPoint.CustomerPoint.Y = circle.Center.Y;
                temp.Diameter = circle.Diameter;
                AVInfo.ACirList.Add(temp);
            }
            else if (entity is Arc arc)
            {
                MixedCAD_Arc temp = new MixedCAD_Arc();
                //Has Sequence
                if (arc.StartPoint.Y > arc.EndPoint.Y)
                {
                    temp.StartPoint.CustomerPoint.X = arc.StartPoint.X;
                    temp.StartPoint.CustomerPoint.Y = arc.StartPoint.Y;
                    temp.EndPoint.CustomerPoint.X = arc.EndPoint.X;
                    temp.EndPoint.CustomerPoint.Y = arc.EndPoint.Y;
                }
                else
                {
                    temp.StartPoint.CustomerPoint.X = arc.EndPoint.X;
                    temp.StartPoint.CustomerPoint.Y = arc.EndPoint.Y;
                    temp.EndPoint.CustomerPoint.X = arc.StartPoint.X;
                    temp.EndPoint.CustomerPoint.Y = arc.StartPoint.Y;
                }
                temp.Length = arc.Length;
                temp.Radius = arc.Radius;
                temp.CenterPoint.CustomerPoint.X = arc.Center.X;
                temp.CenterPoint.CustomerPoint.Y = arc.Center.Y;
                AVInfo.AArcList.Add(temp);
            }
            else if (entity is Curve curve)
            {
                double startParam = curve.StartParam;
                double endParam = curve.EndParam;
                List<Point3d> points = new List<Point3d>();
                for (double param = startParam; param <= endParam; param += 0.1)
                {
                    Point3d point = curve.GetPointAtParameter(param);
                    points.Add(point);
                }
                if (points.Count > 1)
                {
                    MixedCAD_Curve cur = new MixedCAD_Curve();
                    double MinX = points.Min(item => item.X);
                    double MaxX = points.Max(item => item.X);
                    double MinY = points.Min(item => item.Y);
                    double MaxY = points.Max(item => item.Y);
                    Point3d MinPointX3d = points.Find(item => item.X == MinX);
                    Point3d MaxPointX3d = points.Find(item => item.X == MaxX);
                    Point3d MinPointY3d = points.Find(item => item.Y == MinY);
                    Point3d MaxPointY3d = points.Find(item => item.Y == MaxY);
                    cur.MinXPoint.CustomerPoint.X = MinPointX3d.X;
                    cur.MinXPoint.CustomerPoint.Y = MinPointX3d.Y;
                    cur.MinXPoint.CustomerPoint.Z = MinPointX3d.Z;
                    cur.MaxXPoint.CustomerPoint.X = MaxPointX3d.X;
                    cur.MaxXPoint.CustomerPoint.Y = MaxPointX3d.Y;
                    cur.MaxXPoint.CustomerPoint.Z = MaxPointX3d.Z;
                    cur.MinYPoint.CustomerPoint.X = MinPointY3d.X;
                    cur.MinYPoint.CustomerPoint.Y = MinPointY3d.Y;
                    cur.MinYPoint.CustomerPoint.Z = MinPointY3d.Z;
                    cur.MaxYPoint.CustomerPoint.X = MaxPointY3d.X;
                    cur.MaxYPoint.CustomerPoint.Y = MaxPointY3d.Y;
                    cur.MaxYPoint.CustomerPoint.Z = MaxPointY3d.Z;
                    AVInfo.ACurvelist.Add(cur);
                }
            }
        }

        //Rec Assem View
        public static void IdentifyAssemblyDraw(List<MixedCAD_Line> TVLList, List<MixedCAD_Circle> TVCirList)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            try
            {
                using (DocumentLock DocLock = doc.LockDocument())
                {
                    Database db = doc.Database;
                    Editor editor = doc.Editor;
                    PromptSelectionOptions pso = new PromptSelectionOptions();
                    pso.MessageForAdding = "\n请框选组装图: ";
                    PromptSelectionResult selectionResult = editor.GetSelection(pso);
                    AssemViewCADInfo AVInfo = new AssemViewCADInfo();
                    List<Polyline> APolyLineList = new List<Polyline>();
                    if (selectionResult.Status == PromptStatus.OK)
                    {
                        try
                        {
                            Extents3d overallExtents = new Extents3d();
                            ObjectId[] objectIds = selectionResult.Value.GetObjectIds();
                            using (Transaction tr = db.TransactionManager.StartTransaction())
                            {
                                foreach (ObjectId objectId in objectIds)
                                {
                                    Entity entity = tr.GetObject(objectId, OpenMode.ForRead) as Entity;
                                    if (entity != null)
                                    {
                                        Extents3d entityExtents = (Extents3d)entity.Bounds;
                                        Boolean blkF = entity is BlockReference;
                                        if (blkF)
                                        {
                                            BlockReference blkRef = entity as BlockReference;
                                            blkRef.UpgradeOpen();
                                            DBObjectCollection explodedObjects = new DBObjectCollection();
                                            blkRef.Explode(explodedObjects);
                                            BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                                            BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                                            foreach (DBObject obj in explodedObjects)
                                            {
                                                btr.AppendEntity(obj as Entity);
                                                tr.AddNewlyCreatedDBObject(obj, true);
                                                if (obj is Entity)
                                                    SetCADDWGAssemblyPlaneData(objectId, APolyLineList, AVInfo, obj as Entity);
                                            }
                                            blkRef.Erase();
                                        }
                                        else
                                            SetCADDWGAssemblyPlaneData(objectId, APolyLineList,AVInfo,entity);
                                        overallExtents.AddExtents(entityExtents);
                                    }
                                }
                                tr.Commit();
                                tr.Dispose();
                                AssemblyViewPicCondiInfo = CU.ViewSelectAreaCondication(overallExtents);
                            }
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                        finally
                        {
                            AVInfo.ATranPolyLList = ProcessPolyLine(APolyLineList);
                            IdentificationAllLogic(TVLList, TVCirList, AVInfo);
                        }
                    }
                    else
                        editor.WriteMessage(UserPromptErrorType.SelectCollectionNull);
                }
            }
            catch(Exception ex)
            {

            }
        }


        public static void DrawCenterLine()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor editor = doc.Editor;
            PromptSelectionResult selectionResult = editor.GetSelection();
            if (selectionResult.Status != PromptStatus.OK)
            {
                editor.WriteMessage("未选择有效对象。");
                return;
            }
            using (Transaction tr = doc.TransactionManager.StartTransaction())
            {
                BlockTable bt = tr.GetObject(doc.Database.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                SelectionSet selectionSet = selectionResult.Value;
                List<Point3d> centerPointList = new List<Point3d>();
                List<Point3d> allLinePointList = new List<Point3d>();
                foreach (SelectedObject selectedObj in selectionSet)
                {
                    if (selectedObj != null)
                    {
                        Entity entity = tr.GetObject(selectedObj.ObjectId, OpenMode.ForRead) as Entity;
                        Extents3d extents = (Extents3d)entity.Bounds;
                        Point3d center = new Point3d((extents.MaxPoint.X + extents.MinPoint.X) / 2,
                                                     (extents.MaxPoint.Y + extents.MinPoint.Y) / 2,
                                                     (extents.MaxPoint.Z + extents.MinPoint.Z) / 2);
                        allLinePointList.Add(extents.MaxPoint);
                        allLinePointList.Add(extents.MinPoint);
                        centerPointList.Add(center);
                    }
                }
                double centerPX = 0.0;
                if (centerPointList.Count > 0)
                {
                    foreach (var item in centerPointList)
                        centerPX += item.X;
                    centerPX = centerPX / centerPointList.Count;
                }
                double MinY = allLinePointList.Min(element => element.Y);
                double MaxY = allLinePointList.Max(element => element.Y);
                Point3d MinCP = new Point3d(centerPX, MinY, 0);
                Point3d MaxCP = new Point3d(centerPX, MaxY, 0);
                Line centerline = new Line(MinCP, MaxCP);
                centerline.ColorIndex = 1;
                modelSpace.AppendEntity(centerline);
                tr.AddNewlyCreatedDBObject(centerline, true);
                tr.Commit();
            }
            editor.WriteMessage("中心线添加完成。");
        }

        //Process Poly Line(for Meson)
        public static List<MixedCAD_Line> ProcessPolyLine(List<Polyline> pointList)
        {
            List<MixedCAD_Line> resList = new List<MixedCAD_Line>();
            if(pointList.Count > 0)
            {
                for(int i = 0; i <pointList.Count; i++)
                {
                    int numVerts = pointList[i].NumberOfVertices;
                    for (int j = 0; j < numVerts - 1; j++)
                    {
                        MixedCAD_Line temp = new MixedCAD_Line();
                        Point2d pt1 = pointList[i].GetPoint2dAt(j);
                        Point2d pt2 = pointList[i].GetPoint2dAt(j + 1);
                        temp.StartPoint.CustomerPoint.X = pt1.X;
                        temp.StartPoint.CustomerPoint.Y = pt1.Y;
                        temp.EndPoint.CustomerPoint.X = pt2.X;
                        temp.EndPoint.CustomerPoint.Y = pt2.Y;
                        temp.ColorInfo.ColorIndex = pointList[i].ColorIndex.ToString();
                        temp.ColorInfo.ColorNameForDisplay = pointList[i].Color.ColorNameForDisplay;
                        temp.LayerName = pointList[i].Layer;
                        temp = TransCADItemLineData(temp);
                        if(temp.LineType == CADLineType.XDirLine)
                            temp.Length = Math.Abs(Math.Round(pt1.X - pt2.X, 1));
                        if (temp.LineType == CADLineType.YDirLine)
                            temp.Length = Math.Abs(Math.Round(pt1.Y - pt2.Y, 1));
                        resList.Add(temp);
                    }
                    if(numVerts > 2)
                    {
                        MixedCAD_Line fltemp = new MixedCAD_Line();
                        Point2d firstPt = pointList[i].GetPoint2dAt(0);
                        Point2d lastPt = pointList[i].GetPoint2dAt(numVerts - 1);
                        fltemp.StartPoint.CustomerPoint.X = firstPt.X;
                        fltemp.StartPoint.CustomerPoint.Y = firstPt.Y;
                        fltemp.EndPoint.CustomerPoint.X = lastPt.X;
                        fltemp.EndPoint.CustomerPoint.Y = lastPt.Y;
                        fltemp.ColorInfo.ColorIndex = pointList[i].ColorIndex.ToString();
                        fltemp.ColorInfo.ColorNameForDisplay = pointList[i].Color.ColorNameForDisplay;
                        fltemp.LayerName = pointList[i].Layer;
                        fltemp = TransCADItemLineData(fltemp);
                        if (fltemp.LineType == CADLineType.XDirLine)
                            fltemp.Length = Math.Abs(Math.Round(firstPt.X - lastPt.X, 1));
                        if (fltemp.LineType == CADLineType.YDirLine)
                            fltemp.Length = Math.Abs(Math.Round(firstPt.Y - lastPt.Y, 1));
                        resList.Add(fltemp);
                    }
                }
            }
            return resList;
        }

        public static string GetNowCustomerDWGDoc()
        {
            string docName = null;
            DocumentCollection docCol = Application.DocumentManager;
            Document currentDoc = docCol.MdiActiveDocument;
            if (currentDoc != null)
                docName = currentDoc.Name;
            return docName;
        }

        //Rember Now View Customer DWG Document
        public static void RemCustomerDWGDoc()
        {
            string docName = GetNowCustomerDWGDoc();
            if(docName != null)
                AssemblyShareData.OperCustomerDocName = docName;
        }

        //Clear Info Before Afresh Rec
        public static void ClearAVData()
        {
            //ReSet
            dataForm.gpRevCheckBox.Checked = false;
            dataForm.gpOverSpCheckBox.Checked = false;
            dataForm.rpOverSpCheckBox.Checked = false;
            ShareItemBoardShipInfo.extraShipInfo.gpRevFlag = false;
            ShareItemBoardShipInfo.extraShipInfo.gpOverSpFlag = false;
            ShareItemBoardShipInfo.extraShipInfo.rpOverSpFlag = false;
            AssemblyShareData.ASectionList = new List<BoardSectionItem>(AssemblyShareData.AUIBlueSectionList);
            HoleCandidateShareData.SmallScrewCList = new List<ScrewHole>();
            HoleCandidateShareData.BigScrewCList = new List<ScrewHole>();
            HoleCandidateShareData.FallerScrewCList = new List<ScrewHole>();
            HoleCandidateShareData.ReturnPinCList = new List<ScrewHole>();
            HoleCandidateShareData.GPScrewCList = new List<ScrewHole>();
            HoleCandidateShareData.SPScrewCList = new List<ScrewHole>();
            HoleCandidateShareData.EGPScrewCList = new List<ScrewHole>();
            WholeTopViewData.TransverseLineDic.Clear();
            WholeTopViewData.VerticalLineDic.Clear();
            WholeTopViewData.CircleDic.Clear();
            WholeTopViewData.TopViewCenterLineList = new List<MixedCAD_Line>();

            //WholeTopViewData.TopViewHCenterLine = new CAD_Line();
            WholeTopViewData.ModlCenterInfo = new MixedCAD_Point();
            WholeTopViewData.ArcList = new List<MixedCAD_Arc>();
            WholeTopViewData.EGPConnCircleDic = new Dictionary<CircleKey, List<MixedCAD_Circle>>();
            WholeTopViewData.MostLLength = 0;

            TopViewShareData.TopViewBlockCircleList = new List<MixedCAD_Circle>();
            //TopViewShareData.TopViewCircleList = new List<CAD_Circle>();
            AssemblyShareData.egpProcessinfo = new EGPProcessinfo();
            AssemblyShareData.sHoleProcessInfo = new SHoleProcessInfo();
            AssemblyShareData.koHoleProcessinfo = new KOHoleProcessInfo();

            //Clear About Item Info
            ShareItemData.ItemList = new List<SingleItem>();
            ShareItemData.UIItemList = new List<SingleItem>();
            ShareItemData.SurplusItemList = new List<LabourSingleItem>();
            ShareItemData.UISurplusItemList = new List<LabourSingleItem>();
            ParamsConfigData.RecommendDimDic = new Dictionary<string, int>();

            //Clear About Fangtie Info 
            FangtieShareData.FType = FangtieType.None;
            FangtieShareData.HasLRF = false;
            FangtieShareData.FLXInfo = null;
            FangtieShareData.FRXInfo = null;
            FangtieShareData.NOFLXInfo = null;
            FangtieShareData.NOFLXInfo = null;
            FangtieShareData.SPAnotherFX = 0.0;
            FangtieShareData.reckLFInfo = new ReckFangtieInfo();
            FangtieShareData.reckRFInfo = new ReckFangtieInfo();
            FangtieShareData.reckCFInfo = new ReckFangtieInfo();
        }

        //Rec Frame Step 1 Top View
        public static void RecognizeBoardTopViewFrame(int boardRowIndex)
        {
            Document doc = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor editor = doc.Editor;
            CJudgeType BJ = CJudgeType.NONE;
            List<FullInfoLine> blockFrameLineList = new List<FullInfoLine>();
            List<MixedCAD_Arc> blockFrameArcList = new List<MixedCAD_Arc>();
            var selectionResult = editor.GetEntity(UserPromptType.UserSelectTopViewFrameLine);
            if (selectionResult.Status == PromptStatus.OK)
            {
                ObjectId objectId = selectionResult.ObjectId;
                using (Transaction transaction = db.TransactionManager.StartTransaction())
                {
                    Entity entity = transaction.GetObject(objectId, OpenMode.ForRead) as Entity;
                    if (entity != null)
                    {
                        if (entity is Line line)
                        {
                            MixedCAD_Line temp = new MixedCAD_Line();
                            temp.StartPoint.CustomerPoint.X = line.StartPoint.X;
                            temp.StartPoint.CustomerPoint.Y = line.StartPoint.Y;
                            temp.EndPoint.CustomerPoint.X = line.EndPoint.X;
                            temp.EndPoint.CustomerPoint.Y = line.EndPoint.Y;
                            temp.Length = line.Length;
                            temp.ColorInfo.ColorIndex = line.Color.ColorIndex.ToString();
                            temp.ColorInfo.ColorNameForDisplay = line.Color.ColorNameForDisplay;
                            temp.LayerName = line.Layer;
                            temp = TransCADItemLineData(temp);
                            BJ = CJudgeType.N;
                            NonBlockCTVFData(temp);
                        }
                        if(entity is Polyline polyline)
                        {
                            List<FullInfoLine> tempCLineList = new List<FullInfoLine>();
                            List<MixedCAD_Arc> tempArcList = new List<MixedCAD_Arc>();
                            DBObjectCollection explodedObjects = new DBObjectCollection();
                            entity.Explode(explodedObjects);
                            foreach (DBObject dbo in explodedObjects)
                            {
                                if (dbo is Line BILine)
                                {
                                    MixedCAD_Line temp = new MixedCAD_Line();
                                    temp.StartPoint.CustomerPoint.X = BILine.StartPoint.X;
                                    temp.StartPoint.CustomerPoint.Y = BILine.StartPoint.Y;
                                    temp.EndPoint.CustomerPoint.X = BILine.EndPoint.X;
                                    temp.EndPoint.CustomerPoint.Y = BILine.EndPoint.Y;
                                    temp.Length = BILine.Length;
                                    temp.ColorInfo.ColorIndex = BILine.Color.ColorIndex.ToString();
                                    temp.ColorInfo.ColorNameForDisplay = BILine.Color.ColorNameForDisplay;
                                    temp.LayerName = BILine.Layer;
                                    temp = TransCADItemLineData(temp);
                                    FullInfoLine info = new FullInfoLine();
                                    info.LineType = temp.LineType;
                                    info.StartPoint = temp.StartPoint;
                                    info.EndPoint = temp.EndPoint;
                                    info.RealLength = Math.Abs(temp.StartPoint.CustomerPoint.Y - temp.EndPoint.CustomerPoint.Y);
                                    if (temp.SPChamferFlag)
                                        info.RealLength += Math.Abs(temp.SCLine.StartPoint.CustomerPoint.Y - temp.SCLine.EndPoint.CustomerPoint.Y);
                                    if (temp.EPChamferFlag)
                                        info.RealLength += Math.Abs(temp.ECLine.StartPoint.CustomerPoint.Y - temp.ECLine.EndPoint.CustomerPoint.Y);
                                    tempCLineList.Add(info);
                                }
                                if(dbo is Arc arcItem)
                                {
                                    MixedCAD_Arc temp = new MixedCAD_Arc();
                                    temp.CAD_ObjectId = objectId;
                                    if (arcItem.StartPoint.Y > arcItem.EndPoint.Y)
                                    {
                                        temp.StartPoint.CustomerPoint.X = arcItem.StartPoint.X;
                                        temp.StartPoint.CustomerPoint.Y = arcItem.StartPoint.Y;
                                        temp.EndPoint.CustomerPoint.X = arcItem.EndPoint.X;
                                        temp.EndPoint.CustomerPoint.Y = arcItem.EndPoint.Y;
                                    }
                                    else
                                    {
                                        temp.StartPoint.CustomerPoint.X = arcItem.EndPoint.X;
                                        temp.StartPoint.CustomerPoint.Y = arcItem.EndPoint.Y;
                                        temp.EndPoint.CustomerPoint.X = arcItem.StartPoint.X;
                                        temp.EndPoint.CustomerPoint.Y = arcItem.StartPoint.Y;
                                    }
                                    temp.Length = arcItem.Length;
                                    temp.Radius = arcItem.Radius;
                                    temp.CenterPoint.CustomerPoint.X = arcItem.Center.X;
                                    temp.CenterPoint.CustomerPoint.Y = arcItem.Center.Y;
                                    temp.Angle = arcItem.Length / (2 * Math.PI * arcItem.Radius) * 360;
                                    tempArcList.Add(temp);
                                }
                            }
                            BJ = CJudgeType.Y;
                            ExplodeTVFramePixelData(tempCLineList, tempArcList);
                        }
                        // TO EDIT
                        if (entity is BlockReference blockRef)
                        {
                            Point3d blkPos = blockRef.Position;
                            BlockTableRecord BlockItem = transaction.GetObject(blockRef.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
                            foreach (ObjectId BobjectId in BlockItem)
                            {
                                DBObject dbObj = transaction.GetObject(BobjectId, OpenMode.ForRead);
                                if (dbObj is Line)
                                {
                                    Line BILine = dbObj as Line;
                                    MixedCAD_Line temp = new MixedCAD_Line();
                                    temp.StartPoint.CustomerPoint.X = BILine.StartPoint.X;
                                    temp.StartPoint.CustomerPoint.Y = BILine.StartPoint.Y;
                                    temp.EndPoint.CustomerPoint.X = BILine.EndPoint.X;
                                    temp.EndPoint.CustomerPoint.Y = BILine.EndPoint.Y;
                                    temp.Length = BILine.Length;
                                    temp.ColorInfo.ColorIndex = BILine.Color.ColorIndex.ToString();
                                    temp.ColorInfo.ColorNameForDisplay = BILine.Color.ColorNameForDisplay;
                                    temp.LayerName = BILine.Layer;
                                    temp = TransCADItemLineData(temp);
                                    FullInfoLine info = new FullInfoLine();
                                    info.LineType = temp.LineType;
                                    info.StartPoint = temp.StartPoint;
                                    info.EndPoint = temp.EndPoint;
                                    info.RealLength = Math.Abs(temp.StartPoint.CustomerPoint.Y - temp.EndPoint.CustomerPoint.Y);
                                    if (temp.SPChamferFlag)
                                        info.RealLength += Math.Abs(temp.SCLine.StartPoint.CustomerPoint.Y - temp.SCLine.EndPoint.CustomerPoint.Y);
                                    if (temp.EPChamferFlag)
                                        info.RealLength += Math.Abs(temp.ECLine.StartPoint.CustomerPoint.Y - temp.ECLine.EndPoint.CustomerPoint.Y);
                                    blockFrameLineList.Add(info);
                                }
                                if (dbObj is Arc)
                                {
                                    Arc BIArc = dbObj as Arc;
                                    MixedCAD_Arc temp = new MixedCAD_Arc();
                                    temp.CAD_ObjectId = objectId;
                                    if (BIArc.StartPoint.Y > BIArc.EndPoint.Y)
                                    {
                                        temp.StartPoint.CustomerPoint.X = BIArc.StartPoint.X;
                                        temp.StartPoint.CustomerPoint.Y = BIArc.StartPoint.Y;
                                        temp.EndPoint.CustomerPoint.X = BIArc.EndPoint.X;
                                        temp.EndPoint.CustomerPoint.Y = BIArc.EndPoint.Y;
                                    }
                                    else
                                    {
                                        temp.StartPoint.CustomerPoint.X = BIArc.EndPoint.X;
                                        temp.StartPoint.CustomerPoint.Y = BIArc.EndPoint.Y;
                                        temp.EndPoint.CustomerPoint.X = BIArc.StartPoint.X;
                                        temp.EndPoint.CustomerPoint.Y = BIArc.StartPoint.Y;
                                    }
                                    temp.Length = BIArc.Length;
                                    temp.Radius = BIArc.Radius;
                                    temp.CenterPoint.CustomerPoint.X = BIArc.Center.X;
                                    temp.CenterPoint.CustomerPoint.Y = BIArc.Center.Y;
                                    temp.Angle = BIArc.Length / (2 * Math.PI * BIArc.Radius) * 360;
                                    blockFrameArcList.Add(temp);
                                }
                            }
                            BJ = CJudgeType.Y;
                            ExplodeTVFramePixelData(blockFrameLineList, blockFrameArcList);
                        }
                    }

                    if(entity != null)
                    {
                        PromptKeywordOptions options = new PromptKeywordOptions("请输入指令[1:继续量框深/2:放弃量框深]:");
                        options.Keywords.Add("1");
                        options.Keywords.Add("2");
                        options.AllowNone = false;
                        PromptResult result = editor.GetKeywords(options);
                        if (result.Status == PromptStatus.OK)
                        {
                            string userInputStr = result.StringResult;
                            if (userInputStr.Equals("1"))
                            {
                                ProcessTopViewFrameData(BJ);
                                RecognizeBoardAssemblyFrame(boardRowIndex);
                            }
                            if (userInputStr.Equals("2"))
                            {
                                ProcessTopViewFrameData(BJ);
                                RecognizeBoardAssemblyFrameButNoDeep(boardRowIndex);
                            }
                        }

                    }

                    transaction.Commit();
                    return;
                }
            }
            else
            {
                editor.WriteMessage(UserPromptErrorType.SelectCollectionNull);
                goto EndRFrameLoop;
            }
            EndRFrameLoop: { }
        }

        public static void RecognizeBoardAssemblyFrameButNoDeep(int boardRowIndex)
        {
            BoardSectionItem targetBoard = AssemblyShareData.AUIBlueSectionList[boardRowIndex];
            FrameSpeRule();
            targetBoard.frameItem = (FrameItem)ConvertUtils.DeepCopyObject(FrameInfoData.FRItem);
            SetFrameItemTig(boardRowIndex);
            AutoTypeCRUIAfterRecognizeEvent(RenderType.AfterRecoginzeFrame);
        }

        //Rec Frame Step 2 Assem View
        public static void RecognizeBoardAssemblyFrame(int boardRowIndex)
        {
            Document doc = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor editor = doc.Editor;
            var selectionResult = editor.GetEntity(UserPromptType.UserSelectAFrameLine);
            if (selectionResult.Status == PromptStatus.OK)
            {
                ObjectId objectId = selectionResult.ObjectId;
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    Entity entity = tr.GetObject(objectId, OpenMode.ForRead) as Entity;
                    if (entity != null)
                    {
                        if (entity is Line line)
                        {
                            MixedCAD_Line temp = new MixedCAD_Line();
                            temp.StartPoint.CustomerPoint.X = line.StartPoint.X;
                            temp.StartPoint.CustomerPoint.Y = line.StartPoint.Y;
                            temp.EndPoint.CustomerPoint.X = line.EndPoint.X;
                            temp.EndPoint.CustomerPoint.Y = line.EndPoint.Y;
                            temp.Length = line.Length;
                            temp.ColorInfo.ColorIndex = line.Color.ColorIndex.ToString();
                            temp.ColorInfo.ColorNameForDisplay = line.Color.ColorNameForDisplay;
                            temp.LayerName = line.Layer;
                            temp = TransCADItemLineData(temp);
                            if (temp.LineType == CADLineType.YDirLine)
                            {
                                ProcessBoardAssemblyFrameData(temp, boardRowIndex);
                                editor.WriteMessage(UserPromptType.SelectAFrameDepthLine);
                            }
                            else
                                editor.WriteMessage(UserPromptErrorType.FrameDepthNotVLine);
                        }
                        if(entity is Polyline polyline)
                        {
                            List<MixedCAD_Line> tempCLineList = new List<MixedCAD_Line>();
                            DBObjectCollection explodedObjects = new DBObjectCollection();
                            entity.Explode(explodedObjects);
                            foreach (DBObject dbo in explodedObjects)
                            {
                                if(dbo is Line lineItem)
                                {
                                    MixedCAD_Line temp = new MixedCAD_Line();
                                    temp.StartPoint.CustomerPoint.X = lineItem.StartPoint.X;
                                    temp.StartPoint.CustomerPoint.Y = lineItem.StartPoint.Y;
                                    temp.EndPoint.CustomerPoint.X = lineItem.EndPoint.X;
                                    temp.EndPoint.CustomerPoint.Y = lineItem.EndPoint.Y;
                                    temp.Length = lineItem.Length;
                                    temp.ColorInfo.ColorIndex = lineItem.Color.ColorIndex.ToString();
                                    temp.ColorInfo.ColorNameForDisplay = lineItem.Color.ColorNameForDisplay;
                                    temp.LayerName = lineItem.Layer;
                                    temp = TransCADItemLineData(temp);
                                    if (temp.LineType == CADLineType.YDirLine)
                                        tempCLineList.Add(temp);
                                }
                            }
                            if(tempCLineList.Count > 0)
                            {
                                ProcessBoardAssemblyFrameData(tempCLineList[0], boardRowIndex);
                                editor.WriteMessage(UserPromptType.SelectAFrameDepthLine);
                            }
                        }
                    }
                    tr.Commit();
                }
            }
            else
            {
                editor.WriteMessage(UserPromptErrorType.SelectCollectionNull);
                goto EndAFrameLoop;
            }
            EndAFrameLoop: {  }
        }

        public static void SetCADDWGPlaneData(ObjectId objectId, List<Polyline> TVPolyLineList,TopViewCADInfo topViewCADInfo,Entity entity)
        {
            Extents3d entityExtents = (Extents3d)entity.Bounds;
            if (entity is DBText text)
            {
                MixedCAD_Text Item = new MixedCAD_Text();
                Item.CAD_ObjectId = objectId;
                Item.PositionPoint = new MixedCAD_Point();
                Item.PositionPoint.CustomerPoint.X = text.Position.X;
                Item.PositionPoint.CustomerPoint.Y = text.Position.Y;
                Item.Centent = text.TextString;
                topViewCADInfo.TVTextList.Add(Item);
            }
            if (entity is MText mtext)
            {
                Point3d TextPoint = mtext.GeometricExtents.MinPoint;
                MixedCAD_Text Item = new MixedCAD_Text();
                Item.CAD_ObjectId = objectId;
                Item.PositionPoint = new MixedCAD_Point();
                Item.PositionPoint.CustomerPoint.X = TextPoint.X;
                Item.PositionPoint.CustomerPoint.Y = TextPoint.Y;
                Item.Centent = mtext.Text;
                topViewCADInfo.TVTextList.Add(Item);
            }
            if (entity is Line line)
            {
                if (line.Linetype.Contains("CENTER") || line.Linetype == "EB_DASHDOT")
                {
                    MixedCAD_Line temp = new MixedCAD_Line();
                    temp.LayerName = line.Layer;
                    temp.StartPoint.CustomerPoint.X = line.StartPoint.X;
                    temp.StartPoint.CustomerPoint.Y = line.StartPoint.Y;
                    temp.EndPoint.CustomerPoint.X = line.EndPoint.X;
                    temp.EndPoint.CustomerPoint.Y = line.EndPoint.Y;
                    temp.Length = line.Length;
                    temp.ColorInfo.ColorIndex = line.Color.ColorIndex.ToString();
                    temp.ColorInfo.ColorNameForDisplay = line.Color.ColorNameForDisplay;
                    temp.LayerName = line.Layer;
                    temp = TransCADItemLineData(temp);
                    WholeTopViewData.TopViewCenterLineList.Add(temp);
                }
                else
                {
                    MixedCAD_Line temp = new MixedCAD_Line();
                    temp.LayerName = line.Layer;
                    temp.StartPoint.CustomerPoint.X = line.StartPoint.X;
                    temp.StartPoint.CustomerPoint.Y = line.StartPoint.Y;
                    temp.EndPoint.CustomerPoint.X = line.EndPoint.X;
                    temp.EndPoint.CustomerPoint.Y = line.EndPoint.Y;
                    temp.Length = line.Length;
                    temp.ColorInfo.ColorIndex = line.Color.ColorIndex.ToString();
                    temp.ColorInfo.ColorNameForDisplay = line.Color.ColorNameForDisplay;
                    temp.LayerName = line.Layer;
                    temp = TransCADItemLineData(temp);
                    topViewCADInfo.TVLList.Add(temp);
                }
            }
            if (entity is Circle circle)
            {
                MixedCAD_Circle temp = new MixedCAD_Circle();
                temp.CAD_ObjectId = objectId;
                temp.CenterPoint.CustomerPoint.X = circle.Center.X;
                temp.CenterPoint.CustomerPoint.Y = circle.Center.Y;
                temp.Diameter = circle.Diameter;
                topViewCADInfo.TVCirList.Add(temp);
            }
            if (entity is Arc arc)
            {
                MixedCAD_Arc temp = new MixedCAD_Arc();
                temp.CAD_ObjectId = objectId;
                if (arc.StartPoint.Y > arc.EndPoint.Y)
                {
                    temp.StartPoint.CustomerPoint.X = arc.StartPoint.X;
                    temp.StartPoint.CustomerPoint.Y = arc.StartPoint.Y;
                    temp.EndPoint.CustomerPoint.X = arc.EndPoint.X;
                    temp.EndPoint.CustomerPoint.Y = arc.EndPoint.Y;
                }
                else
                {
                    temp.StartPoint.CustomerPoint.X = arc.EndPoint.X;
                    temp.StartPoint.CustomerPoint.Y = arc.EndPoint.Y;
                    temp.EndPoint.CustomerPoint.X = arc.StartPoint.X;
                    temp.EndPoint.CustomerPoint.Y = arc.StartPoint.Y;
                }
                temp.Length = arc.Length;
                temp.Radius = arc.Radius;
                temp.CenterPoint.CustomerPoint.X = arc.Center.X;
                temp.CenterPoint.CustomerPoint.Y = arc.Center.Y;
                temp.Angle = arc.Length / (2 * Math.PI * arc.Radius) * 360;
                WholeTopViewData.ArcList.Add(temp);
            }
            if (entity is Polyline polyline)
                TVPolyLineList.Add(polyline);
        }

        //Rec Top View
        public static void IdentifyStep()
        {
            List<Polyline> TVPolyLineList = new List<Polyline>();
            ClearAVData();
            Document doc = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor editor = doc.Editor;
            PromptSelectionOptions pso = new PromptSelectionOptions();
            pso.MessageForAdding = "\n请框选平面图: ";
            PromptSelectionResult selectionResult = editor.GetSelection(pso);
            TopViewCADInfo topViewCADInfo = new TopViewCADInfo();
            GetBatchNumByCustomDraw();
            if (selectionResult.Status == PromptStatus.OK)
            {
                DocumentLock m_DocumentLock = doc.LockDocument();
                try
                {
                    ObjectId[] objectIds = selectionResult.Value.GetObjectIds();
                    Extents3d overallExtents = new Extents3d();
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        foreach (ObjectId objectId in objectIds)
                        {
                            Entity entity = tr.GetObject(objectId, OpenMode.ForRead) as Entity;
                            if (entity != null)
                            {
                                Extents3d entityExtents = (Extents3d)entity.Bounds;
                                Boolean blkF = entity is BlockReference;
                                if (blkF)
                                {
                                    BlockReference blkRef = entity as BlockReference;
                                    blkRef.UpgradeOpen();
                                    DBObjectCollection explodedObjects = new DBObjectCollection();
                                    blkRef.Explode(explodedObjects);
                                    BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                                    foreach (DBObject obj in explodedObjects)
                                    {
                                        btr.AppendEntity(obj as Entity);
                                        tr.AddNewlyCreatedDBObject(obj, true);
                                        if (obj is Entity)
                                            SetCADDWGPlaneData(objectId, TVPolyLineList, topViewCADInfo, obj as Entity);
                                    }
                                    blkRef.Erase();
                                }
                                else
                                    SetCADDWGPlaneData(objectId, TVPolyLineList, topViewCADInfo, entity);
                                overallExtents.AddExtents(entityExtents);
                            }
                        }
                        tr.Commit();
                    }
                    TopViewPicCondiInfo = CU.ViewSelectAreaCondication(overallExtents);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    if(TVPolyLineList.Count > 0)
                    {
                        List<MixedCAD_Line> afterPPList = ProcessPolyLine(TVPolyLineList);
                        topViewCADInfo.TVLList.AddRange(afterPPList);
                    }
                    if (m_DocumentLock != null)
                        m_DocumentLock.Dispose();
                }
            }
            else
            {
                editor.WriteMessage(UserPromptErrorType.SelectCollectionNull);
                goto EndTopViewLoop;
            }
            editor.WriteMessage(UserPromptType.SuceessRTopView);
            ProcessTopViewAllLogic(topViewCADInfo);
            IdentifyAssemblyDraw(topViewCADInfo.TVLList,topViewCADInfo.TVCirList);
            EndTopViewLoop: { }
        }

        //Compare TV View & Assem View TLine Dep For Check
        private static Boolean TVAndAssemViewTLineDep(List<MixedCAD_Line> TVTLine, List<MixedCAD_Line> AVTLine)
        {
            Boolean Res = false;
            for (int i = 0; i < TVTLine.Count; i++)
            {
                for(int j = 0; j < AVTLine.Count; j++)
                {
                    Boolean F1 = TVTLine[i].StartPoint.CustomerPoint.X == AVTLine[j].StartPoint.CustomerPoint.X;
                    Boolean F2 = TVTLine[i].StartPoint.CustomerPoint.Y == AVTLine[j].StartPoint.CustomerPoint.Y;
                    Boolean F3 = TVTLine[i].EndPoint.CustomerPoint.X == AVTLine[j].EndPoint.CustomerPoint.X;
                    Boolean F4 = TVTLine[i].EndPoint.CustomerPoint.Y == AVTLine[j].EndPoint.CustomerPoint.Y;
                    Boolean F5 = TVTLine[i].LayerName.Equals(AVTLine[j].LayerName);
                    if(F1 && F2 && F3 && F4 &&  F5)
                    {
                        Res = true;
                        break;
                    }
                }
                if (Res) break;
            }
            return Res;
        }

        //Get Mold Num Info
        private static async void GetBatchNumByCustomDraw()   
        {
            DwgFileInfo nowFileInfo = CADAuxiliaryUtils.GetCurrentDrawingPath();
            string[] pathSplitArray = nowFileInfo.complePath.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries);
            if (pathSplitArray.Length >= 2)
            {
                string fileName = pathSplitArray[pathSplitArray.Length - 1];
                string mesOrder = pathSplitArray[pathSplitArray.Length - 2];
                string quabatchNum = await HttpUtils.AskQuaNumber(fileName,mesOrder);
                if (quabatchNum != null)
                    dataForm.BatchNumBox.Texts = quabatchNum;
            }
        }

        public static void GrabModeNumber()
        {
            string ModeNum = null;
            Document doc = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor editor = doc.Editor;
            var selectionResult = editor.GetEntity(UserPromptType.UserSelectModeNum);
            if (selectionResult.Status == PromptStatus.OK)
            {
                ObjectId objectId = selectionResult.ObjectId;
                using (Transaction transaction = db.TransactionManager.StartTransaction())
                {
                    Entity entity = transaction.GetObject(objectId, OpenMode.ForRead) as Entity;
                    if (entity is DBText text)
                    {
                        ModeNum = text.TextString;
                        ModeNum = CU.FilterChinseStr(ModeNum);
                    }
                    else if (entity is MText mtext)
                    {
                        string textContent = mtext.Text;
                        string[] MTextList = textContent.Split(new string[] { "\r\n" }, StringSplitOptions.None);
                        ModeNum = textContent.ToString().Trim();
                        ModeNum = CU.FilterChinseStr(ModeNum);
                    }
                    transaction.Commit();
                }
            }
            if (ModeNum != null)
                CallSetModeNum(ModeNum);
        }

        //Trans To CAD Line -> CAD_Line
        public static MixedCAD_Line TransCADItemLineData(MixedCAD_Line line)
        {
            MixedCAD_Line temp = new MixedCAD_Line();
            temp.StartPoint = new MixedCAD_Point();
            temp.EndPoint = new MixedCAD_Point();
            temp.IsBlockEleFlag = line.IsBlockEleFlag;
            temp.ColorInfo.ColorIndex = line.ColorInfo.ColorIndex;
            temp.ColorInfo.ColorNameForDisplay = line.ColorInfo.ColorNameForDisplay;
            temp.LayerName = line.LayerName;
            double errorDifX = 0;
            double errorDifY = 0;
            double X1 = Math.Round(line.StartPoint.CustomerPoint.X, 1);
            double X2 = Math.Round(line.EndPoint.CustomerPoint.X, 1);
            double Y1 = Math.Round(line.StartPoint.CustomerPoint.Y, 1);
            double Y2 = Math.Round(line.EndPoint.CustomerPoint.Y, 1);
            if(X1 != X2)
            {
                double DiffX = Math.Abs(X1 - X2);
                if (DiffX > 50)
                    errorDifX = 0.25;
                else
                    errorDifX = 0.1;
            }
            if(Y1 != Y2)
            {
               double DiffY = Math.Abs(Y1 - Y2);
                if (DiffY > 50)
                    errorDifY = 0.25;
                else
                    errorDifY = 0.1;
            }

            Boolean XF = X1 - errorDifX <= X2 && X2 <= X1 + errorDifX;
            Boolean YF = Y1 - errorDifY <= Y2 && Y2 <= Y1 + errorDifY;

            if(!XF && YF)
            {
                //TLine StartPoint.CustomerPoint.X > EndPoint X
                if (line.StartPoint.CustomerPoint.X < line.EndPoint.CustomerPoint.X)
                {
                    temp.StartPoint.CustomerPoint.X = Math.Round(line.StartPoint.CustomerPoint.X, 3);
                    temp.StartPoint.CustomerPoint.Y = Math.Round(line.StartPoint.CustomerPoint.Y, 3);
                    temp.StartPoint.CustomerPoint.Z = Math.Round(line.StartPoint.CustomerPoint.Z, 3);
                    temp.EndPoint.CustomerPoint.X = Math.Round(line.EndPoint.CustomerPoint.X, 3);
                    temp.EndPoint.CustomerPoint.Y = Math.Round(line.EndPoint.CustomerPoint.Y, 3);
                    temp.EndPoint.CustomerPoint.Z = Math.Round(line.EndPoint.CustomerPoint.Z, 3);
                }
                else
                {
                    temp.StartPoint.CustomerPoint.X = Math.Round(line.EndPoint.CustomerPoint.X, 3);
                    temp.StartPoint.CustomerPoint.Y = Math.Round(line.EndPoint.CustomerPoint.Y, 3);
                    temp.StartPoint.CustomerPoint.Z = Math.Round(line.EndPoint.CustomerPoint.Z, 3);
                    temp.EndPoint.CustomerPoint.X = Math.Round(line.StartPoint.CustomerPoint.X, 3);
                    temp.EndPoint.CustomerPoint.Y = Math.Round(line.StartPoint.CustomerPoint.Y, 3);
                    temp.EndPoint.CustomerPoint.Z = Math.Round(line.StartPoint.CustomerPoint.Z, 3);
                }
                temp.LineType = CADLineType.XDirLine;
            }

            if (XF && !YF)
            {
                //YLine StartPoint.CustomerPoint.Y > EndPoint Y
                if (line.StartPoint.CustomerPoint.Y > line.EndPoint.CustomerPoint.Y)
                {
                    temp.StartPoint.CustomerPoint.X = Math.Round(line.StartPoint.CustomerPoint.X, 3);
                    temp.StartPoint.CustomerPoint.Y = Math.Round(line.StartPoint.CustomerPoint.Y, 3);
                    temp.StartPoint.CustomerPoint.Z = Math.Round(line.StartPoint.CustomerPoint.Z, 3);
                    temp.EndPoint.CustomerPoint.X = Math.Round(line.EndPoint.CustomerPoint.X, 3);
                    temp.EndPoint.CustomerPoint.Y = Math.Round(line.EndPoint.CustomerPoint.Y, 3);
                    temp.EndPoint.CustomerPoint.Z = Math.Round(line.EndPoint.CustomerPoint.Z, 3);
                }
                else
                {
                    temp.StartPoint.CustomerPoint.X = Math.Round(line.EndPoint.CustomerPoint.X, 3);
                    temp.StartPoint.CustomerPoint.Y = Math.Round(line.EndPoint.CustomerPoint.Y, 3);
                    temp.StartPoint.CustomerPoint.Z = Math.Round(line.EndPoint.CustomerPoint.Z, 3);
                    temp.EndPoint.CustomerPoint.X = Math.Round(line.StartPoint.CustomerPoint.X, 3);
                    temp.EndPoint.CustomerPoint.Y = Math.Round(line.StartPoint.CustomerPoint.Y, 3);
                    temp.EndPoint.CustomerPoint.Z = Math.Round(line.StartPoint.CustomerPoint.Z, 3);
                }
                temp.LineType = CADLineType.YDirLine;
            }

            if(!XF && !YF)
            {
                //OBLine StartPoint.CustomerPoint.Y > EndPoint Y
                if (line.StartPoint.CustomerPoint.Y > line.EndPoint.CustomerPoint.Y)
                {
                    temp.StartPoint.CustomerPoint.X = Math.Round(line.StartPoint.CustomerPoint.X, 3);
                    temp.StartPoint.CustomerPoint.Y = Math.Round(line.StartPoint.CustomerPoint.Y, 3);
                    temp.StartPoint.CustomerPoint.Z = Math.Round(line.StartPoint.CustomerPoint.Z, 3);
                    temp.EndPoint.CustomerPoint.X = Math.Round(line.EndPoint.CustomerPoint.X, 3);
                    temp.EndPoint.CustomerPoint.Y = Math.Round(line.EndPoint.CustomerPoint.Y, 3);
                    temp.EndPoint.CustomerPoint.Z = Math.Round(line.EndPoint.CustomerPoint.Z, 3);
                }
                else
                {
                    temp.StartPoint.CustomerPoint.X = Math.Round(line.EndPoint.CustomerPoint.X, 3);
                    temp.StartPoint.CustomerPoint.Y = Math.Round(line.EndPoint.CustomerPoint.Y, 3);
                    temp.StartPoint.CustomerPoint.Z = Math.Round(line.EndPoint.CustomerPoint.Z, 3);
                    temp.EndPoint.CustomerPoint.X = Math.Round(line.StartPoint.CustomerPoint.X, 3);
                    temp.EndPoint.CustomerPoint.Y = Math.Round(line.StartPoint.CustomerPoint.Y, 3);
                    temp.EndPoint.CustomerPoint.Z = Math.Round(line.StartPoint.CustomerPoint.Z, 3);
                }
                temp.LineType = CADLineType.ObliqueLine;
            }
            temp.Length = line.Length;
            return temp;
        }

        // DWG MoldSize Length
        public static void CalculateMoldSizeByTVInfo(List<FullInfoLine> XCadLineList, List<FullInfoLine> YCadLineList)
        {
            double? MostLLength = null;
            double? MostWLength = null;
            if(XCadLineList.Count > 0)
                MostLLength = XCadLineList.Max(item => item.RealLength);
            if(YCadLineList.Count > 0)
                MostWLength = YCadLineList.Max(item => item.RealLength);
            if(MostLLength != null && MostWLength != null)
                WholeTopViewData.MostLLength = (double)MostLLength < (double)MostWLength ? (double)MostLLength : (double)MostWLength;

            double? YCLength = null;
            if(XCadLineList.Count > 0)
            {
                double XMaxL = XCadLineList.Select(item => item.RealLength).Max();
                XMaxL = Math.Round(XMaxL, 1);
                int targetXIndex = XCadLineList.FindIndex(item => item.RealLength == XMaxL);
                //string targetXColorIndex = XCadLineList[targetXIndex].ColorInfo.ColorIndex;
                //XCadLineList = XCadLineList.FindAll(item => item.ColorInfo.ColorIndex.Equals(targetXColorIndex));
                //Filter Disturb
                List<FullInfoLine> targetList = XCadLineList.FindAll(item => item.RealLength > XMaxL / 5);
                List<FullInfoLine> MaxXLList = XCadLineList.FindAll(item => item.RealLength == XMaxL);
                List<double> XList = XCadLineList.Select(item => item.RealLength).Distinct().ToList();
                if (MaxXLList.Count >= 2)
                {
                    List<double> XYList = targetList.Select(item => item.StartPoint.CustomerPoint.Y).ToList();
                    double MaxY = XYList.Max();
                    double MinY = XYList.Min();
                    MoldBaseShare.tvInfo.canCalF = true;
                    MoldBaseShare.tvInfo.TVMaxY = MaxY;
                    MoldBaseShare.tvInfo.TVMinY = MinY;
                    double targetL = Math.Round(MaxY - MinY,2);
                    MoldBaseShare.Length = targetL;
                }
                else
                {
                    List<double> TVYList = targetList.Select(item => item.StartPoint.CustomerPoint.Y).ToList();
                    double MaxY = TVYList.Max();
                    double MinY = TVYList.Min();
                    MoldBaseShare.tvInfo.canCalF = true;
                    MoldBaseShare.tvInfo.TVMaxY = MaxY;
                    MoldBaseShare.tvInfo.TVMinY = MinY;
                    double targetL = Math.Round(MaxY - MinY, 2);
                    MoldBaseShare.Length = targetL;
                }
            }
        }

        public static void ProcessTopViewAllLogic(TopViewCADInfo TVInfo)
        {
            List<MixedCAD_Line> TVLList = TVInfo.TVLList;
            List<MixedCAD_Circle> TVCirList = TVInfo.TVCirList;
            List<MixedCAD_Text> TVTextList = TVInfo.TVTextList;
            ProcessTopViewLine(TVInfo.TVLList, WholeTopViewData);
            List<FullInfoLine> ResXLineList = new List<FullInfoLine>();
            List<double> tvXKeyList = WholeTopViewData.TransverseLineDic.Keys.ToList();
            if(tvXKeyList.Count > 0)
            {
                for (int i = 0; i < tvXKeyList.Count; i++)
                {
                    List<FullInfoLine> tempList = WholeTopViewData.TransverseLineDic[tvXKeyList[i]];
                    ResXLineList.AddRange(tempList);
                }
            }
            List<FullInfoLine> ResYLineList = new List<FullInfoLine>();
            List<double> tvYKeyList = WholeTopViewData.VerticalLineDic.Keys.ToList();
            if (tvYKeyList.Count > 0)
            {
                for (int i = 0; i < tvYKeyList.Count; i++)
                {
                    List<FullInfoLine> tempList = WholeTopViewData.VerticalLineDic[tvYKeyList[i]];
                    ResYLineList.AddRange(tempList);
                }
            }
            CalculateMoldSizeByTVInfo(ResXLineList, ResYLineList);
            //Calculate TV Center Coor
            ImTVRefCustomerCenterCoor(TVLList);
            //Trans To Relative Coor
            CU.ImTVPixFullRefCoor(TVInfo);
            Dictionary<CircleKey, List<MixedCAD_Circle>> tempallConCirDic = CU.ProcessConCircles(TVCirList);
            Dictionary<string, List<ConSpeCircle>> ConSpeCirDic = CU.TranMergeConSpeCircle(tempallConCirDic);
            Dictionary<CircleKey, List<MixedCAD_Circle>> EGPConnCircleDic = ProcessTVMayBeEGP(tempallConCirDic, TVTextList);
            Dictionary<string, List<ConSpeCircle>> EGPConSpeCirDic = CU.TranMergeConSpeCircle(EGPConnCircleDic);
            if (EGPConSpeCirDic.Count > 0)
                ConSpeCirDic = CU.FilterEGPSpe(ConSpeCirDic, EGPConSpeCirDic);
            CU.FilterSameCoorEGP(EGPConSpeCirDic);
            WholeTopViewData.EGPConnCircleDic = EGPConnCircleDic;
            WholeTopViewData.CircleDic = ConSpeCirDic;
        }

        public static void ATypeDrawTVCruxLabel(ObjectId textStyleId,List<MixedCAD_Line> CadLineList,Boolean IShareF) 
        {
            List<MixedCAD_Line> yList = CadLineList.FindAll(item => item.LineType == CADLineType.YDirLine).ToList();
            double maxYL = yList.Select(item => item.Length).Max();
            double filterYL = maxYL / 5;
            yList = yList.FindAll(item => item.Length > filterYL);
            double levelL = maxYL - 6;
            double heighL = maxYL + 6;

            List<MixedCAD_Line> LList = yList.FindAll(item => levelL <= item.Length && item.Length <= heighL).ToList();
            LList = LList.OrderBy(item => item.StartPoint.CustomerPoint.X).ToList();

            List<MixedCAD_Line> xList = CadLineList.FindAll(item => item.LineType == CADLineType.XDirLine).ToList();
            double maxXL = xList.Select(item => item.Length).Max();
            double filterXL = maxXL / 5;
            xList = xList.FindAll(item => item.Length > filterXL);

            List<double> LYList = xList.Select(item => item.StartPoint.CustomerPoint.Y).ToList();
            if(LYList.Count > 0)
            {
                double boardMaxY = LYList.Max();
                double boardMinY = LYList.Min();
                MixedCAD_Line targetLine = xList.Find(item => item.StartPoint.CustomerPoint.Y == boardMaxY);
                double targetX = targetLine.StartPoint.CustomerPoint.X;
                Point3d Point1 = new Point3d(targetX, boardMaxY, 0);
                Point3d Point2 = new Point3d(targetX, boardMinY, 0);
                CADAuxiliaryUtils.ATypeDrawBoardAndItemLabel(textStyleId,Point1, Point2, -20, 0,"B","Y",0);
            }
            List<BoardSectionItem> FList = AssemblyShareData.ASectionList.FindAll(item => item.BoardCode.Equals("fangtie")).ToList();
            Boolean FF = FList.Count() >= 2;
            Boolean epfpF = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("epBoard") 
            || item.BoardCode.Equals("fpBoard")) != -1;
            if (IShareF)
            {
                if (LList.Count >= 2)
                {
                    //I Shape
                    double ISX = LList[0].StartPoint.CustomerPoint.X;
                    double ISY =  LList[0].StartPoint.CustomerPoint.Y;
                    double IEX = LList[LList.Count - 1].StartPoint.CustomerPoint.X;
                    double IEY = LList[LList.Count - 1].StartPoint.CustomerPoint.Y;
                    if (ISY != IEY)
                        IEY = ISY;
                    Point3d ISPoint = new Point3d(ISX, ISY,0);
                    Point3d IEPoint = new Point3d(IEX, IEY,0);
                    CADAuxiliaryUtils.ATypeDrawBoardAndItemLabel(textStyleId,ISPoint, IEPoint,0,40);
                    if (LList.Count >= 4)
                    {
                        double AboutFSX = LList[1].StartPoint.CustomerPoint.X;
                        double AboutFSY = LList[1].StartPoint.CustomerPoint.Y;
                        double AboutFEX = LList[LList.Count - 2].StartPoint.CustomerPoint.X;
                        double AboutFEY = LList[LList.Count - 2].StartPoint.CustomerPoint.Y;
                        if (AboutFEY != AboutFSY)
                            AboutFEY = AboutFSY;
                        Point3d AboutFSPoint = new Point3d(AboutFSX, AboutFSY, 0);
                        Point3d AboutFEPoint = new Point3d(AboutFEX, AboutFEY, 0);
                        CADAuxiliaryUtils.ATypeDrawBoardAndItemLabel(textStyleId,AboutFSPoint, AboutFEPoint,0,30);
                        if (LList.Count >= 6)
                        {
                            //Fangtie
                            double F1EX = LList[2].StartPoint.CustomerPoint.X;
                            double F1EY = LList[2].StartPoint.CustomerPoint.Y;
                            Point3d F1SPoint = new Point3d(AboutFSX, F1EY, 0);
                            Point3d F1EPoint = new Point3d(F1EX, F1EY, 0);
                            CADAuxiliaryUtils.ATypeDrawBoardAndItemLabel(textStyleId,F1SPoint, F1EPoint,0,20);
                            double F2SX = LList[LList.Count - 3].StartPoint.CustomerPoint.X;
                            double F2SY = LList[LList.Count - 3].StartPoint.CustomerPoint.Y;
                            Point3d F2SPoint = new Point3d(F2SX, F2SY, 0);
                            Point3d F2EPoint = new Point3d(AboutFEX, F2SY, 0);
                            CADAuxiliaryUtils.ATypeDrawBoardAndItemLabel(textStyleId,F2SPoint, F2EPoint,0,20);
                            if (LList.Count >= 8)
                            {
                                //epfpBoard
                                double epfpSX = LList[3].StartPoint.CustomerPoint.X;
                                double epfpSY = LList[3].StartPoint.CustomerPoint.Y;
                                double epfpEX = LList[LList.Count - 4].StartPoint.CustomerPoint.X;
                                double epfpEY = LList[LList.Count - 4].StartPoint.CustomerPoint.Y;
                                if (epfpEY != epfpSY)
                                    epfpEY = epfpSY;
                                Point3d epfpSPoint = new Point3d(epfpSX, epfpSY, 0);
                                Point3d epfpEPoint = new Point3d(epfpEX, epfpEY, 0);
                                CADAuxiliaryUtils.ATypeDrawBoardAndItemLabel(textStyleId,epfpSPoint, epfpEPoint,0,10);
                            }
                        }
                    }
                }
            }
            else
            {
                int LNum = LList.Count;
                int halfIndex = -1;
                //Top Panel
                double HSX = LList[0].StartPoint.CustomerPoint.X;
                double HSY = LList[0].StartPoint.CustomerPoint.Y;
                double HEX = LList[LList.Count - 1].StartPoint.CustomerPoint.X;
                double HEY = LList[LList.Count - 1].StartPoint.CustomerPoint.Y;
                Point3d topPoint = new Point3d(HSX, HSY, 0);
                Point3d topEPoint = new Point3d(HEX, HEY, 0);
                CADAuxiliaryUtils.ATypeDrawBoardAndItemLabel(textStyleId,topPoint, topEPoint, 0, 40);
                if (LNum % 2 == 0)
                    halfIndex = LNum / 2 - 1;
                else
                    halfIndex = LNum / 2 - 2;
                if(halfIndex - 1 > 0 && halfIndex + 1 < LNum - 1)
                {
                    //epfpBoard
                    if (epfpF)
                    {
                        double epSX = LList[halfIndex].StartPoint.CustomerPoint.X;
                        double epSY = LList[halfIndex].StartPoint.CustomerPoint.Y;
                        double epEX = LList[halfIndex + 1].StartPoint.CustomerPoint.X;
                        double epEY = LList[halfIndex + 1].StartPoint.CustomerPoint.Y;
                        if (epEY != epSY)
                            epEY = epSY;
                        Point3d epPoint = new Point3d(epSX, epSY, 0);
                        Point3d epEPoint = new Point3d(epEX, epEY, 0);
                        CADAuxiliaryUtils.ATypeDrawBoardAndItemLabel(textStyleId,epPoint, epEPoint, 0, 10);
                    }
                }
                //Fangite
                if (FF)
                {
                    //L
                    if(halfIndex - 2 >= 0)
                    {
                        double LFSX = LList[halfIndex - 1].StartPoint.CustomerPoint.X;
                        double LFSY = LList[halfIndex - 1].StartPoint.CustomerPoint.Y;
                        double LFEX = LList[halfIndex - 2].StartPoint.CustomerPoint.X;
                        double LFEY = LList[halfIndex - 2].StartPoint.CustomerPoint.Y;
                        if (LFSY != LFEY)
                            LFEY = LFSY;
                        Point3d LFPoint = new Point3d(LFSX, LFSY, 0);
                        Point3d LFEPoint = new Point3d(LFEX, LFEY, 0);
                        CADAuxiliaryUtils.ATypeDrawBoardAndItemLabel(textStyleId,LFPoint, LFEPoint, 0, 20);
                    }
                    //R
                    if (halfIndex + 3 <= LNum - 1)
                    {
                        double RFSX = LList[halfIndex + 2].StartPoint.CustomerPoint.X;
                        double RFSY = LList[halfIndex + 2].StartPoint.CustomerPoint.Y;
                        double RFEX = LList[halfIndex + 3].StartPoint.CustomerPoint.X;
                        double RFEY = LList[halfIndex + 3].StartPoint.CustomerPoint.Y;
                        if (RFSY != RFEY)
                            RFEY = RFSY;
                        Point3d RFPoint = new Point3d(RFSX, RFSY, 0);
                        Point3d RFEPoint = new Point3d(RFEX, RFEY, 0);
                        CADAuxiliaryUtils.ATypeDrawBoardAndItemLabel(textStyleId,RFPoint, RFEPoint, 0, 20);
                    }
                }
            }
            
        }

        public static void ATypeDrawAssemblyViewCruxLabel(ObjectId dimStyleId)
        {
            List<BoardSectionItem> operList = AssemblyShareData.ASectionList;
            FullInfoLine lastLineInfo = operList[operList.Count - 1].BottomLine;
            double refY = lastLineInfo.StartPoint.CustomerPoint.Y;
            double bpSX = lastLineInfo.StartPoint.CustomerPoint.X;
            double bpEX = lastLineInfo.EndPoint.CustomerPoint.X;
            Point3d bpSPoint = new Point3d(bpSX, refY, 0);
            Point3d bpEPoint = new Point3d(bpEX, refY, 0);
            CADAuxiliaryUtils.ATypeDrawBoardAndItemLabel(dimStyleId,bpSPoint, bpEPoint,0,-40);
            if (FangtieShareData.HasLRF)
            {
                ReckFangtieInfo LFInfo = FangtieShareData.reckLFInfo;
                ReckFangtieInfo RFInfo = FangtieShareData.reckRFInfo;
                if(LFInfo.Width > 0 && RFInfo.Width > 0)
                {
                    double FLXInfo = (double)LFInfo.LX;
                    double FRXInfo = (double)RFInfo.RX;
                    Point3d FSPoint = new Point3d(FLXInfo, refY, 0);
                    Point3d FEPoint = new Point3d(FRXInfo, refY , 0);
                    CADAuxiliaryUtils.ATypeDrawBoardAndItemLabel(dimStyleId,FSPoint, FEPoint,0,-30);
                    if(FangtieShareData.FLXInfo != null)
                    {
                        double LFRX = (double)LFInfo.RX;
                        Point3d LFRXPoint = new Point3d(LFRX, refY, 0);
                        CADAuxiliaryUtils.ATypeDrawBoardAndItemLabel(dimStyleId,FSPoint, LFRXPoint,0,-20);
                    }
                    if(FangtieShareData.FRXInfo != null)
                    {
                        double RFLX = (double)RFInfo.LX;
                        Point3d RFLXPoint = new Point3d(RFLX, refY, 0);
                        CADAuxiliaryUtils.ATypeDrawBoardAndItemLabel(dimStyleId,RFLXPoint, FEPoint,0,-20);
                    }
                }
            }
            //epfpBoard
            List<BoardSectionItem> epfpBoardList = AssemblyShareData.ASectionList.FindAll(item => item.BoardCode.Equals("epBoard") 
            || item.BoardCode.Equals("fpBoard"));
            if (epfpBoardList.Count > 0)
            {
                List<double> epfpRXList = epfpBoardList.Select(item => (double)item.boardLRBoundInfo.BoardRX).ToList();
                List<double> epfpLXList = epfpBoardList.Select(item => (double)item.boardLRBoundInfo.BoardLX).ToList();
                double epfpLX = epfpLXList.Min();
                double epfpRX = epfpRXList.Min();
                Point3d epfpSPoint = new Point3d(epfpLX, refY, 0);
                Point3d epfpEPoint = new Point3d(epfpRX, refY, 0);
                CADAuxiliaryUtils.ATypeDrawBoardAndItemLabel(dimStyleId,epfpSPoint, epfpEPoint, 0, -10);
            }
        }

        public static void ATypeDrawAssemSPGPRPLabel(ObjectId dimStyleId)
        {
            List<SingleItem> ItemList = ShareItemData.ItemList;
            if(ItemList.Count > 0)
            {
                SingleItem RPItem = ItemList.Find(item => item.ItemNameType == DItemNameType.ReturnPin);
                if (RPItem != null)
                {
                    if(RPItem.PeakY != null && RPItem.NadirY != null)
                    {
                        double RPmaxY = (double)RPItem.PeakY;
                        double RPminY = (double)RPItem.NadirY;
                        double RPCX = RPItem.AVCustomerCX;
                        Point3d RPSPoint = new Point3d(RPCX, RPmaxY, 0);
                        Point3d RPEPoint = new Point3d(RPCX, RPminY, 0);
                        double dimLavelY = (RPmaxY - RPminY) * 0.15 + RPminY;
                        double dimLX = RPCX - RPItem.Dim / 2;
                        double dimRX = RPCX + RPItem.Dim / 2;
                        Point3d dimPoint1 = new Point3d(dimLX, dimLavelY,0);
                        Point3d dimPoint2 = new Point3d(dimRX, dimLavelY,0);
                        CADAuxiliaryUtils.ATypeDrawBoardAndItemLabel(dimStyleId,dimPoint1, dimPoint2, 0, 0,"I","X",RPItem.Dim);
                        CADAuxiliaryUtils.ATypeDrawBoardAndItemLabel(dimStyleId, RPSPoint, RPEPoint, 0, 0,"I","X",RPItem.Dim);
                    }
                }

                SingleItem GPItem = ItemList.Find(item => item.ItemNameType == DItemNameType.GuidePin);
                if (GPItem != null)
                {
                    if(GPItem.PeakY != null && GPItem.NadirY != null)
                    {
                        double GPmaxY = (double)GPItem.PeakY;
                        double GPminY = (double)GPItem.NadirY;
                        double GPCX = GPItem.AVCustomerCX;
                        Point3d GPSPoint = new Point3d(GPCX, GPmaxY, 0);
                        Point3d GPEPoint = new Point3d(GPCX, GPminY, 0);
                        double dimLavelY = (GPmaxY - GPminY) * 0.15 + GPminY;
                        double dimLX = GPCX - GPItem.Dim / 2;
                        double dimRX = GPCX + GPItem.Dim / 2;
                        Point3d dimPoint1 = new Point3d(dimLX, dimLavelY, 0);
                        Point3d dimPoint2 = new Point3d(dimRX, dimLavelY, 0);
                        CADAuxiliaryUtils.ATypeDrawBoardAndItemLabel(dimStyleId, dimPoint1, dimPoint2, 0, 0, "I", "X", GPItem.Dim);
                        CADAuxiliaryUtils.ATypeDrawBoardAndItemLabel(dimStyleId, GPSPoint, GPEPoint, 0, 0, "I", "X", GPItem.Dim);
                    }
                }

                SingleItem SPItem = ItemList.Find(item => item.ItemNameType == DItemNameType.SupportPin
                || item.ItemNameType == DItemNameType.NoNozzleMesonSupportPin);
                if (SPItem != null)
                {
                    if(SPItem.PeakY != null && SPItem.NadirY != null)
                    {
                        double SPmaxY = (double)SPItem.PeakY;
                        double SPminY = (double)SPItem.NadirY;
                        double SPCX = SPItem.AVCustomerCX;
                        Point3d SPSPoint = new Point3d(SPCX, SPmaxY, 0);
                        Point3d SPEPoint = new Point3d(SPCX, SPminY, 0);
                        double dimLavelY = (SPmaxY - SPminY) * 0.15 + SPminY;
                        double dimLX = SPCX - SPItem.Dim / 2;
                        double dimRX = SPCX + SPItem.Dim / 2;
                        Point3d dimPoint1 = new Point3d(dimLX, dimLavelY, 0);
                        Point3d dimPoint2 = new Point3d(dimRX, dimLavelY, 0);
                        CADAuxiliaryUtils.ATypeDrawBoardAndItemLabel(dimStyleId, dimPoint1, dimPoint2, 0, 0, "I", "X", SPItem.Dim);
                        CADAuxiliaryUtils.ATypeDrawBoardAndItemLabel(dimStyleId, SPSPoint, SPEPoint, 0, 0, "I", "X", SPItem.Dim);
                    }
                }

                SingleItem TopScrewItem = ItemList.Find(item => item.ItemNameType == DItemNameType.TopPanelScrew);
                if(TopScrewItem != null)
                {
                    if (TopScrewItem.PeakY != null && TopScrewItem.NadirY != null)
                    {
                        double tpmaxY = (double)TopScrewItem.PeakY;
                        double tpminY = (double)TopScrewItem.NadirY;
                        // TO Check
                        double TPCX = TopScrewItem.AVCustomerCX;
                        double dimLavelY = (tpmaxY - tpminY) * 0.15 + tpminY;
                        double dimLX = TPCX - TopScrewItem.Dim / 2;
                        double dimRX = TPCX + TopScrewItem.Dim / 2;
                        Point3d dimPoint1 = new Point3d(dimLX, dimLavelY, 0);
                        Point3d dimPoint2 = new Point3d(dimRX, dimLavelY, 0);
                        CADAuxiliaryUtils.ATypeDrawBoardAndItemLabel(dimStyleId, dimPoint1, dimPoint2, 0, 0, "I", "X", TopScrewItem.Dim);
                    }
                }

                SingleItem FScrewItem = ItemList.Find(item => item.ItemNameType == DItemNameType.SpaceBlockScrew);
                if (FScrewItem != null)
                {
                    if(FScrewItem.PeakY != null && FScrewItem.NadirY != null)
                    {
                        double fmaxY = (double)FScrewItem.PeakY;
                        double fminY = (double)FScrewItem.NadirY;
                        double FCX = FScrewItem.AVCustomerCX;
                        double dimLavelY = (fmaxY - fminY) * 0.15 + fminY;
                        double dimLX = FCX - FScrewItem.Dim / 2;
                        double dimRX = FCX + FScrewItem.Dim / 2;
                        Point3d dimPoint1 = new Point3d(dimLX, dimLavelY, 0);
                        Point3d dimPoint2 = new Point3d(dimRX, dimLavelY, 0);
                        CADAuxiliaryUtils.ATypeDrawBoardAndItemLabel(dimStyleId, dimPoint1, dimPoint2, 0, 0, "I", "X", FScrewItem.Dim);
                    }
                }
            
                SingleItem epfpcrewItem = ItemList.Find(item => item.ItemNameType == DItemNameType.PinBoardScrew);
                if (epfpcrewItem != null)
                {
                    if(epfpcrewItem.PeakY != null && epfpcrewItem.NadirY != null)
                    {
                        double epmaxY = (double)epfpcrewItem.PeakY;
                        double epminY = (double)epfpcrewItem.NadirY;
                        double EPCX = epfpcrewItem.AVCustomerCX;
                        double dimLavelY = (epmaxY - epminY) * 0.5 + epminY;
                        double dimLX = EPCX - epfpcrewItem.Dim / 2;
                        double dimRX = EPCX + epfpcrewItem.Dim / 2;
                        Point3d dimPoint1 = new Point3d(dimLX, dimLavelY, 0);
                        Point3d dimPoint2 = new Point3d(dimRX, dimLavelY, 0);
                        CADAuxiliaryUtils.ATypeDrawBoardAndItemLabel(dimStyleId, dimPoint1, dimPoint2, 0, 0, "I", "X", epfpcrewItem.Dim);
                    }
                }

                SingleItem bpcrewItem = ItemList.Find(item => item.ItemNameType == DItemNameType.BottomPanelScrew);
                if (bpcrewItem != null)
                {
                    if(bpcrewItem.PeakY != null && bpcrewItem.NadirY != null)
                    {
                        double bpmaxY = (double)bpcrewItem.PeakY;
                        double bpminY = (double)bpcrewItem.NadirY;
                        double BPCX = bpcrewItem.AVCustomerCX;
                        double dimLavelY = (bpmaxY - bpminY) * 0.5 + bpminY;
                        double dimLX = BPCX - bpcrewItem.Dim / 2;
                        double dimRX = BPCX + bpcrewItem.Dim / 2;
                        Point3d dimPoint1 = new Point3d(dimLX, dimLavelY, 0);
                        Point3d dimPoint2 = new Point3d(dimRX, dimLavelY, 0);
                        CADAuxiliaryUtils.ATypeDrawBoardAndItemLabel(dimStyleId, dimPoint1, dimPoint2, 0, 0, "I", "X", bpcrewItem.Dim);
                    }
                }

            }
        }

        //YLine X L->R Y Top -> Bottom List -> Dic
        public static Dictionary<double, List<FullInfoLine>> OrderlyConvertYVerLinesToDic(List<MixedCAD_Line> CadLineList)
        {
            Dictionary<double, List<FullInfoLine>> ResYDic = new Dictionary<double, List<FullInfoLine>>();
            List<MixedCAD_Line> operYDicList = CadLineList.OrderByDescending(item => item.StartPoint.CustomerPoint.X).ThenBy(item => item.StartPoint.CustomerPoint.Y)
               .Where(item => item.LineType == CADLineType.YDirLine).ToList();
            for (int i = 0; i < operYDicList.Count; i++)
            {
                if (ResYDic.ContainsKey(operYDicList[i].StartPoint.CustomerPoint.X))
                {
                    List<FullInfoLine> target = ResYDic[operYDicList[i].StartPoint.CustomerPoint.X];
                    MixedCAD_Line temp = operYDicList[i];
                    FullInfoLine info = new FullInfoLine();
                    info.LineType = temp.LineType;
                    info.StartPoint = temp.StartPoint;
                    info.EndPoint = temp.EndPoint;
                    info.RealLength = Math.Abs(temp.StartPoint.CustomerPoint.Y - temp.EndPoint.CustomerPoint.Y);
                    if (temp.SPChamferFlag)
                        info.RealLength += Math.Abs(temp.SCLine.StartPoint.CustomerPoint.Y - temp.SCLine.EndPoint.CustomerPoint.Y);
                    if (temp.EPChamferFlag)
                        info.RealLength += Math.Abs(temp.ECLine.StartPoint.CustomerPoint.Y - temp.ECLine.EndPoint.CustomerPoint.Y);
                    target.Add(info);
                }
                else
                {
                    MixedCAD_Line temp = operYDicList[i];
                    FullInfoLine info = new FullInfoLine();
                    info.LineType = temp.LineType;
                    info.StartPoint = temp.StartPoint;
                    info.EndPoint = temp.EndPoint;
                    info.RealLength = Math.Abs(temp.StartPoint.CustomerPoint.Y - temp.EndPoint.CustomerPoint.Y);
                    if (temp.SPChamferFlag)
                        info.RealLength += Math.Abs(temp.SCLine.StartPoint.CustomerPoint.Y - temp.SCLine.EndPoint.CustomerPoint.Y);
                    if (temp.EPChamferFlag)
                        info.RealLength += Math.Abs(temp.ECLine.StartPoint.CustomerPoint.Y - temp.ECLine.EndPoint.CustomerPoint.Y);
                    ResYDic.Add(operYDicList[i].StartPoint.CustomerPoint.X, new List<FullInfoLine>() { info });
                }
            }
            return ResYDic;
        }

        //XLine X L->R Y Top -> Bottom List -> Dic
        public static Dictionary<double, List<FullInfoLine>> OrderlyConvertXVerLinesToDic(List<MixedCAD_Line> CadLineList)
        {
            Dictionary<double, List<FullInfoLine>> ResXDic = new Dictionary<double, List<FullInfoLine>>();
            List<MixedCAD_Line> XDirLineList = CadLineList.OrderByDescending(item => item.StartPoint.CustomerPoint.X).ThenBy(item => item.StartPoint.CustomerPoint.Y)
                .Where(item => item.LineType == CADLineType.XDirLine).ToList();
            for (int i = 0; i < XDirLineList.Count; i++)
            {
                if (ResXDic.ContainsKey(XDirLineList[i].StartPoint.CustomerPoint.X))
                {
                    List<FullInfoLine> target = ResXDic[XDirLineList[i].StartPoint.CustomerPoint.X];
                    MixedCAD_Line temp = XDirLineList[i];
                    FullInfoLine info = new FullInfoLine();
                    info.LineType = temp.LineType;
                    info.StartPoint = temp.StartPoint;
                    info.EndPoint = temp.EndPoint;
                    info.RealLength = Math.Abs(temp.StartPoint.CustomerPoint.X - temp.EndPoint.CustomerPoint.X);
                    if (temp.SPChamferFlag)
                        info.RealLength += Math.Abs(temp.SCLine.StartPoint.CustomerPoint.X - temp.SCLine.EndPoint.CustomerPoint.X);
                    if (temp.EPChamferFlag)
                        info.RealLength += Math.Abs(temp.ECLine.StartPoint.CustomerPoint.X - temp.ECLine.EndPoint.CustomerPoint.X);
                    target.Add(info);
                }
                else
                {
                    MixedCAD_Line temp = XDirLineList[i];
                    FullInfoLine info = new FullInfoLine();
                    info.LineType = temp.LineType;
                    info.StartPoint = temp.StartPoint;
                    info.EndPoint = temp.EndPoint;
                    info.RealLength = Math.Abs(temp.StartPoint.CustomerPoint.X - temp.EndPoint.CustomerPoint.X);
                    if (temp.SPChamferFlag)
                        info.RealLength += Math.Abs(temp.SCLine.StartPoint.CustomerPoint.X - temp.SCLine.EndPoint.CustomerPoint.X);
                    if (temp.EPChamferFlag)
                        info.RealLength += Math.Abs(temp.ECLine.StartPoint.CustomerPoint.X - temp.ECLine.EndPoint.CustomerPoint.X);
                    ResXDic.Add(XDirLineList[i].StartPoint.CustomerPoint.X, new List<FullInfoLine>() { info });
                }
            }
            return ResXDic;
        }

        public static void ProcessTopViewLine(List<MixedCAD_Line> CadLineList, TopViewInfoData res)
        {
            List<MixedCAD_Line> XDirLineList = CadLineList.FindAll(item => item.LineType == CADLineType.XDirLine).ToList();
            List<MixedCAD_Line> YDirLineList = CadLineList.FindAll(item => item.LineType == CADLineType.YDirLine).ToList();
            //obliqueLine
            List<MixedCAD_Line> ImObliqueLineList = CadLineList.Where(item => item.LineType == CADLineType.ObliqueLine).ToList();
            for (int i = 0; i < ImObliqueLineList.Count; i++)
            {
                var obItem = ImObliqueLineList[i];
                //TLine Relevance with ob 
                if (XDirLineList.Count > 0)
                {
                    for (int j = 0; j < XDirLineList.Count; j++)
                    {
                        LineJoinType targetType = ComputedUtils.JudgeTOLineConn(XDirLineList[j], obItem);
                        Boolean F = targetType != LineJoinType.None;
                        if (F)
                            ComputedUtils.AssSegmentTOLineConn(targetType, XDirLineList[j], obItem);
                    }
                }
                //VLine Relevance width ob 
                if (YDirLineList.Count > 0)
                {
                    for (int j = 0; j < YDirLineList.Count; j++)
                    {
                        LineJoinType targetType = ComputedUtils.JudgeTOLineConn(YDirLineList[j], obItem);
                        Boolean F = targetType != LineJoinType.None;
                        if (F)
                            ComputedUtils.AssSegmentTOLineConn(targetType, YDirLineList[j], obItem);
                    }
                }
            }
            res.TransverseLineDic = OrderlyConvertXVerLinesToDic(XDirLineList);
            res.VerticalLineDic = OrderlyConvertYVerLinesToDic(YDirLineList);
        }

        //Block Top View Tidy Up Frame Info 
        public static void ExplodeTVFramePixelData(List<FullInfoLine> BLineList, List<MixedCAD_Arc> BArcList)
        {
            //Clear Init last Time Info
            FrameInfoData.FCList.Clear();
            List<FullInfoLine> OperLineList = (List<FullInfoLine>)ConvertUtils.DeepCopyObject(BLineList);
            List<MixedCAD_Arc> tempArcList = (List<MixedCAD_Arc>)ConvertUtils.DeepCopyObject(BArcList);
            List <FullInfoLine> tempTLineList = OperLineList.FindAll(item => item.LineType == CADLineType.XDirLine).ToList();
            List<FullInfoLine> tempVLineList = OperLineList.FindAll(item => item.LineType == CADLineType.YDirLine).ToList();
            Boolean F1 = tempTLineList.Count > 0;
            Boolean F2 = tempVLineList.Count > 0;
            if (F1 && F2)
            {
                FullInfoLine BeginFLine = tempTLineList[0];
                MixedCAD_Line FirstLine = new MixedCAD_Line();
                FirstLine.StartPoint.CustomerPoint.X = BeginFLine.StartPoint.CustomerPoint.X;
                FirstLine.StartPoint.CustomerPoint.Y = BeginFLine.StartPoint.CustomerPoint.Y;
                FirstLine.EndPoint.CustomerPoint.X = BeginFLine.EndPoint.CustomerPoint.X;
                FirstLine.EndPoint.CustomerPoint.Y = BeginFLine.EndPoint.CustomerPoint.Y;
                FirstLine.Length = BeginFLine.RealLength;
                FirstLine.LineType = BeginFLine.LineType;
                //Scan Point
                MixedCAD_Point ScanP = FirstLine.StartPoint;
                CADLineType NowLType = FirstLine.LineType;
                //Begin Scan
                FrameLineInfo firstInfo = new FrameLineInfo();
                firstInfo.TVLine.StartPoint = FirstLine.StartPoint;
                firstInfo.TVLine.EndPoint = FirstLine.EndPoint;
                firstInfo.TVLine.RealLength = FirstLine.Length;
                firstInfo.SortNum = 1;

                if (NowLType == CADLineType.XDirLine)
                {
                    firstInfo.FLineType = FrameLineType.T;
                    int rfIndex = tempTLineList.FindIndex(item => item.StartPoint.CustomerPoint.X == FirstLine.StartPoint.CustomerPoint.X &&
                    item.StartPoint.CustomerPoint.Y == FirstLine.StartPoint.CustomerPoint.Y && item.EndPoint.CustomerPoint.X == FirstLine.EndPoint.CustomerPoint.X
                    && item.EndPoint.CustomerPoint.X == FirstLine.EndPoint.CustomerPoint.X);
                    tempTLineList.RemoveAt(rfIndex);
                }
                if (NowLType == CADLineType.YDirLine)
                {
                    firstInfo.FLineType = FrameLineType.V;
                    int rfIndex = tempVLineList.FindIndex(item => item.StartPoint.CustomerPoint.X == FirstLine.StartPoint.CustomerPoint.X &&
                   item.StartPoint.CustomerPoint.Y == FirstLine.StartPoint.CustomerPoint.Y && item.EndPoint.CustomerPoint.X == FirstLine.EndPoint.CustomerPoint.X
                   && item.EndPoint.CustomerPoint.X == FirstLine.EndPoint.CustomerPoint.X);
                    tempVLineList.RemoveAt(rfIndex);
                }
                FrameInfoData.FCList.Add(firstInfo);
                int LIndex = 0;
                while (LIndex != -1)
                {
                    //T -> Find V or Arc 
                    if (NowLType == CADLineType.XDirLine)
                    {
                        LIndex = tempVLineList.FindIndex(item => CU.JudgePConnLine(ScanP, item));
                        if (LIndex != -1)
                        {
                            ScanP = CU.GetPJudgeLineAntherP(ScanP, tempVLineList[LIndex]);
                            NowLType = CADLineType.YDirLine;
                            FrameLineInfo adjoinL = new FrameLineInfo();
                            adjoinL.TVLine.StartPoint = tempVLineList[LIndex].StartPoint;
                            adjoinL.TVLine.EndPoint = tempVLineList[LIndex].EndPoint;
                            adjoinL.TVLine.RealLength = tempVLineList[LIndex].RealLength;
                            adjoinL.FLineType = FrameLineType.V;
                            adjoinL.SortNum = FrameInfoData.FCList.Count() + 1;
                            FrameInfoData.FCList.Add(adjoinL);
                            tempVLineList.RemoveAt(LIndex);
                        }
                        else
                        {
                            LIndex = tempArcList.FindIndex(item => CU.JudgePConnArc(ScanP, item));
                            if (LIndex != -1)
                            {
                                ScanP = CU.GetPJudgeArcAntherP(ScanP, tempArcList[LIndex]);
                                NowLType = CADLineType.NONE;
                                FrameLineInfo adjoinL = new FrameLineInfo();
                                adjoinL.ArcLine = (MixedCAD_Arc)ConvertUtils.DeepCopyObject(tempArcList[LIndex]);
                                adjoinL.FLineType = FrameLineType.ARC;
                                adjoinL.SortNum = FrameInfoData.FCList.Count() + 1;
                                FrameInfoData.FCList.Add(adjoinL);
                                tempArcList.RemoveAt(LIndex);
                            }
                        }
                    }
                    //V -> Find T or Arc 
                    if (NowLType == CADLineType.YDirLine)
                    {
                        LIndex = tempTLineList.FindIndex(item => CU.JudgePConnLine(ScanP, item));
                        if (LIndex != -1)
                        {
                            ScanP = CU.GetPJudgeLineAntherP(ScanP, tempTLineList[LIndex]);
                            NowLType = CADLineType.XDirLine;
                            FrameLineInfo adjoinL = new FrameLineInfo();
                            adjoinL.TVLine.StartPoint = tempTLineList[LIndex].StartPoint;
                            adjoinL.TVLine.EndPoint = tempTLineList[LIndex].EndPoint;
                            adjoinL.TVLine.RealLength = tempTLineList[LIndex].RealLength;
                            adjoinL.FLineType = FrameLineType.T;
                            adjoinL.SortNum = FrameInfoData.FCList.Count() + 1;
                            FrameInfoData.FCList.Add(adjoinL);
                            tempTLineList.RemoveAt(LIndex);
                        }
                        else
                        {
                            LIndex = tempArcList.FindIndex(item => CU.JudgePConnArc(ScanP, item));
                            if (LIndex != -1)
                            {
                                ScanP = CU.GetPJudgeArcAntherP(ScanP, tempArcList[LIndex]);
                                NowLType = CADLineType.NONE;
                                FrameLineInfo adjoinL = new FrameLineInfo();
                                adjoinL.ArcLine = (MixedCAD_Arc)ConvertUtils.DeepCopyObject(tempArcList[LIndex]);
                                adjoinL.FLineType = FrameLineType.ARC;
                                adjoinL.SortNum = FrameInfoData.FCList.Count() + 1;
                                FrameInfoData.FCList.Add(adjoinL);
                                tempArcList.RemoveAt(LIndex);
                            }
                        }
                    }
                    //NowLType NONE Arc -> Find T or V
                    if (NowLType == CADLineType.NONE)
                    {
                        LIndex = tempTLineList.FindIndex(item => CU.JudgePConnLine(ScanP, item));
                        if (LIndex != -1)
                        {
                            ScanP = CU.GetPJudgeLineAntherP(ScanP, tempTLineList[LIndex]);
                            NowLType = CADLineType.XDirLine;
                            FrameLineInfo adjoinL = new FrameLineInfo();
                            adjoinL.TVLine.StartPoint = tempTLineList[LIndex].StartPoint;
                            adjoinL.TVLine.EndPoint = tempTLineList[LIndex].EndPoint;
                            adjoinL.TVLine.RealLength = tempTLineList[LIndex].RealLength;
                            adjoinL.FLineType = FrameLineType.T;
                            adjoinL.SortNum = FrameInfoData.FCList.Count() + 1;
                            FrameInfoData.FCList.Add(adjoinL);
                            tempTLineList.RemoveAt(LIndex);
                        }
                        else
                        {
                            LIndex = tempVLineList.FindIndex(item => CU.JudgePConnLine(ScanP, item));
                            if (LIndex != -1)
                            {
                                ScanP = CU.GetPJudgeLineAntherP(ScanP, tempVLineList[LIndex]);
                                NowLType = CADLineType.YDirLine;
                                FrameLineInfo adjoinL = new FrameLineInfo();
                                adjoinL.TVLine.StartPoint = tempVLineList[LIndex].StartPoint;
                                adjoinL.TVLine.EndPoint = tempVLineList[LIndex].EndPoint;
                                adjoinL.TVLine.RealLength = tempVLineList[LIndex].RealLength;
                                adjoinL.FLineType = FrameLineType.V;
                                adjoinL.SortNum = FrameInfoData.FCList.Count() + 1;
                                FrameInfoData.FCList.Add(adjoinL);
                                tempVLineList.RemoveAt(LIndex);
                            }
                        }
                    }
                }
                tempTLineList.Clear();
                tempVLineList.Clear();
                tempArcList.Clear();

            }
            else
            {
                MessageBox.Show(UserPromptErrorType.CanNotRFrameBeforeSelectTV);
                return;
            }

        }

        //Process Special Scene
        public static void FrameSpeRule()
        {
            List<FrameLineInfo> operList = FrameInfoData.FCList;
            FrameItem operItem = FrameInfoData.FRItem;
            Boolean F1 = operItem.BL_Radius == 0;
            Boolean F2 = operItem.BL_Radius == operItem.TL_Radius;
            Boolean F3 = operItem.TL_Radius == operItem.TR_Radius;
            Boolean F4 = operItem.TR_Radius == operItem.BR_Radius;
            if(F1 && F2 && F3 && F4)
            {
                double fd = operItem.FrameDepth;
                double angleValue = ATypeSetDefaultAngleVLogic(fd);
                operItem.TL_Radius = angleValue;
                operItem.TR_Radius = angleValue;
                operItem.BL_Radius = angleValue;
                operItem.BR_Radius = angleValue;
                operItem.TL_Type = AngleType.BK;
                operItem.TR_Type = AngleType.BK;
                operItem.BL_Type = AngleType.BK;
                operItem.BR_Type = AngleType.BK;
            }
        }

        public static double ATypeSetDefaultAngleVLogic(double D)
        {
            double Res = 0.00;
            Boolean D1 = D < 50;
            Boolean D2 = 50 <= D && D < 70;
            Boolean D3 = 70 <= D && D <= 100;
            Boolean D4 = 101 <= D && D <= 180;
            Boolean D5 = 181 <= D && D <= 300;
            //Boolean R2 = cTypeText.Equals("避空");
            if (D1)
                Res = 8.5;
            if (D2)
                Res = 10.5;
            if (D3)
                Res = 13;
            if (D4)
                Res = 17.5;
            if (D5)
                Res = 25;
            return Res;
        }

        //Simple Pixel No Block Top View Tidy Up Frame Info 
        public static void NonBlockCTVFData(MixedCAD_Line TargetLine)
        {
            //Clear Init last Time Info
            FrameInfoData.FCList.Clear();
            Boolean F1 = WholeTopViewData.TransverseLineDic.Keys.Count > 0;
            Boolean F2 = WholeTopViewData.VerticalLineDic.Keys.Count > 0;
            if (F1 && F2)
            {
                List<MixedCAD_Line> topCenterList = WholeTopViewData.TopViewCenterLineList;
                List<FullInfoLine> tempTLineList = new List<FullInfoLine>();
                foreach (KeyValuePair<double, List<FullInfoLine>> kvp in WholeTopViewData.TransverseLineDic)
                    foreach (var item in kvp.Value)
                        tempTLineList.Add(item);
                //MayBe Has CenterStyle TO Draw Frame
                if(topCenterList.Count > 0)
                {
                    List<MixedCAD_Line> tList =  topCenterList.FindAll(item => item.LineType == CADLineType.XDirLine).ToList();
                    if(tList.Count > 0)
                    {
                        for(int i = 0; i < tList.Count; i++)
                        {
                            FullInfoLine item = new FullInfoLine();
                            item.StartPoint.CustomerPoint.X = tList[i].StartPoint.CustomerPoint.X;
                            item.StartPoint.CustomerPoint.Y = tList[i].StartPoint.CustomerPoint.Y;
                            item.EndPoint.CustomerPoint.X = tList[i].EndPoint.CustomerPoint.X;
                            item.EndPoint.CustomerPoint.Y = tList[i].StartPoint.CustomerPoint.Y;
                            item.LineType = tList[i].LineType;
                            item.RealLength = tList[i].Length;
                            tempTLineList.Add(item);
                        }
                    }
                }
                
                List<FullInfoLine> tempVLineList = new List<FullInfoLine>();
                foreach (KeyValuePair<double, List<FullInfoLine>> kvp in WholeTopViewData.VerticalLineDic)
                    foreach (var item in kvp.Value)
                        tempVLineList.Add(item);
                Boolean TNumF = tempTLineList.Count > 0;
                Boolean VNumF = tempVLineList.Count > 0;
                if (topCenterList.Count > 0)
                {
                    List<MixedCAD_Line> yList = topCenterList.FindAll(item => item.LineType == CADLineType.YDirLine).ToList();
                    if (yList.Count > 0)
                    {
                        for (int i = 0; i < yList.Count; i++)
                        {
                            FullInfoLine item = new FullInfoLine();
                            item.StartPoint.CustomerPoint.X = yList[i].StartPoint.CustomerPoint.X;
                            item.StartPoint.CustomerPoint.Y = yList[i].StartPoint.CustomerPoint.Y;
                            item.EndPoint.CustomerPoint.X = yList[i].EndPoint.CustomerPoint.X;
                            item.EndPoint.CustomerPoint.Y = yList[i].StartPoint.CustomerPoint.Y;
                            item.LineType = yList[i].LineType;
                            item.RealLength = yList[i].Length;
                            tempVLineList.Add(item);
                        }
                    }
                }
                List<MixedCAD_Arc> tempArcList = new List<MixedCAD_Arc>(WholeTopViewData.ArcList);
                MixedCAD_Line FirstLine = TargetLine;
                //Scan Point
                MixedCAD_Point ScanP = FirstLine.StartPoint;
                CADLineType NowLType = FirstLine.LineType;
                //Begin Scan
                FrameLineInfo firstInfo = new FrameLineInfo();
                firstInfo.TVLine.StartPoint = FirstLine.StartPoint;
                firstInfo.TVLine.EndPoint = FirstLine.EndPoint;
                firstInfo.TVLine.RealLength = FirstLine.Length;
                firstInfo.SortNum = 1;
                if (NowLType == CADLineType.XDirLine)
                {
                    firstInfo.FLineType = FrameLineType.T;
                    int rfIndex = tempTLineList.FindIndex(item => item.StartPoint.CustomerPoint.X == FirstLine.StartPoint.CustomerPoint.X &&
                    item.StartPoint.CustomerPoint.Y == FirstLine.StartPoint.CustomerPoint.Y && item.EndPoint.CustomerPoint.X == FirstLine.EndPoint.CustomerPoint.X
                    && item.EndPoint.CustomerPoint.X == FirstLine.EndPoint.CustomerPoint.X);
                    tempTLineList.RemoveAt(rfIndex);
                }
                if (NowLType == CADLineType.YDirLine)
                {
                    firstInfo.FLineType = FrameLineType.V;
                    int rfIndex = tempVLineList.FindIndex(item => item.StartPoint.CustomerPoint.X == FirstLine.StartPoint.CustomerPoint.X &&
                   item.StartPoint.CustomerPoint.Y == FirstLine.StartPoint.CustomerPoint.Y && item.EndPoint.CustomerPoint.X == FirstLine.EndPoint.CustomerPoint.X
                   && item.EndPoint.CustomerPoint.X == FirstLine.EndPoint.CustomerPoint.X);
                    tempVLineList.RemoveAt(rfIndex);
                }
                FrameInfoData.FCList.Add(firstInfo);
                int LIndex = 0;
                while (LIndex != -1)
                {
                    //T -> Find V or Arc 
                    if(NowLType == CADLineType.XDirLine)
                    {                            
                        LIndex = tempVLineList.FindIndex(item => CU.JudgePConnLine(ScanP, item));
                        if(LIndex != -1)
                        {
                            ScanP = CU.GetPJudgeLineAntherP(ScanP, tempVLineList[LIndex]);
                            NowLType = CADLineType.YDirLine;
                            FrameLineInfo adjoinL = new FrameLineInfo();
                            adjoinL.TVLine.StartPoint = tempVLineList[LIndex].StartPoint;
                            adjoinL.TVLine.EndPoint = tempVLineList[LIndex].EndPoint;
                            adjoinL.TVLine.RealLength = tempVLineList[LIndex].RealLength;
                            adjoinL.FLineType = FrameLineType.V;
                            adjoinL.SortNum = FrameInfoData.FCList.Count() + 1;
                            FrameInfoData.FCList.Add(adjoinL);
                            tempVLineList.RemoveAt(LIndex);
                        }
                        else
                        {
                            LIndex = tempArcList.FindIndex(item => CU.JudgePConnArc(ScanP, item));
                            if (LIndex != -1)
                            {
                                ScanP = CU.GetPJudgeArcAntherP(ScanP, tempArcList[LIndex]);
                                NowLType = CADLineType.NONE;
                                FrameLineInfo adjoinL = new FrameLineInfo();
                                adjoinL.ArcLine = (MixedCAD_Arc)ConvertUtils.DeepCopyObject(tempArcList[LIndex]);
                                adjoinL.FLineType = FrameLineType.ARC;
                                adjoinL.SortNum = FrameInfoData.FCList.Count() + 1;
                                FrameInfoData.FCList.Add(adjoinL);
                                tempArcList.RemoveAt(LIndex);
                            }
                        }
                    }
                    //V -> Find T or Arc 
                    if (NowLType == CADLineType.YDirLine)
                    {
                        LIndex = tempTLineList.FindIndex(item => CU.JudgePConnLine(ScanP, item));
                        if (LIndex != -1)
                        {
                            ScanP = CU.GetPJudgeLineAntherP(ScanP, tempTLineList[LIndex]);
                            NowLType = CADLineType.XDirLine;
                            FrameLineInfo adjoinL = new FrameLineInfo();
                            adjoinL.TVLine.StartPoint = tempTLineList[LIndex].StartPoint;
                            adjoinL.TVLine.EndPoint = tempTLineList[LIndex].EndPoint;
                            adjoinL.TVLine.RealLength = tempTLineList[LIndex].RealLength;
                            adjoinL.FLineType = FrameLineType.T;
                            adjoinL.SortNum = FrameInfoData.FCList.Count() + 1;
                            FrameInfoData.FCList.Add(adjoinL);
                            tempTLineList.RemoveAt(LIndex);
                        }
                        else
                        {
                            LIndex = tempArcList.FindIndex(item => CU.JudgePConnArc(ScanP, item));
                            if (LIndex != -1)
                            {
                                ScanP = CU.GetPJudgeArcAntherP(ScanP, tempArcList[LIndex]);
                                NowLType = CADLineType.NONE;
                                FrameLineInfo adjoinL = new FrameLineInfo();
                                adjoinL.ArcLine = (MixedCAD_Arc)ConvertUtils.DeepCopyObject(tempArcList[LIndex]);
                                adjoinL.FLineType = FrameLineType.ARC;
                                adjoinL.SortNum = FrameInfoData.FCList.Count() + 1;
                                FrameInfoData.FCList.Add(adjoinL);
                                tempArcList.RemoveAt(LIndex);
                            }
                        }
                    }
                    //NowLType NONE Arc -> Find T or V
                    if (NowLType == CADLineType.NONE)
                    {
                        LIndex = tempTLineList.FindIndex(item => CU.JudgePConnLine(ScanP, item));
                        if (LIndex != -1)
                        {
                            ScanP = CU.GetPJudgeLineAntherP(ScanP, tempTLineList[LIndex]);
                            NowLType = CADLineType.XDirLine;
                            FrameLineInfo adjoinL = new FrameLineInfo();
                            adjoinL.TVLine.StartPoint = tempTLineList[LIndex].StartPoint;
                            adjoinL.TVLine.EndPoint = tempTLineList[LIndex].EndPoint;
                            adjoinL.TVLine.RealLength = tempTLineList[LIndex].RealLength;
                            adjoinL.FLineType = FrameLineType.T;
                            adjoinL.SortNum = FrameInfoData.FCList.Count() + 1;
                            FrameInfoData.FCList.Add(adjoinL);
                            tempTLineList.RemoveAt(LIndex);
                        }
                        else
                        {
                            LIndex = tempVLineList.FindIndex(item => CU.JudgePConnLine(ScanP, item));
                            if (LIndex != -1)
                            {
                                ScanP = CU.GetPJudgeLineAntherP(ScanP, tempVLineList[LIndex]);
                                NowLType = CADLineType.YDirLine;
                                FrameLineInfo adjoinL = new FrameLineInfo();
                                adjoinL.TVLine.StartPoint = tempVLineList[LIndex].StartPoint;
                                adjoinL.TVLine.EndPoint = tempVLineList[LIndex].EndPoint;
                                adjoinL.TVLine.RealLength = tempVLineList[LIndex].RealLength;
                                adjoinL.FLineType = FrameLineType.V;
                                adjoinL.SortNum = FrameInfoData.FCList.Count() + 1;
                                FrameInfoData.FCList.Add(adjoinL);
                                tempVLineList.RemoveAt(LIndex);
                            }
                        }
                    }
                }
                tempTLineList.Clear();
                tempVLineList.Clear();
                tempArcList.Clear();
            }
            else
            {
                MessageBox.Show(UserPromptErrorType.CanNotRFrameBeforeSelectTV);
                return;
            }
        }

        //设置板厚标注信息
        public static void SetBoardDimensionInfo(List<CAD_Dimension> BDList)
        {
            List<CAD_Dimension> resList = new List<CAD_Dimension>();
            List<BoardSectionItem> BoardList =  AssemblyShareData.ASectionList;
            int BNum = BoardList.Count;
            for (int i = 0; i < BNum; i++)
            {
                double? BLX = null;
                double? BRX = null;
                double BTY = BoardList[i].OverheadLine.StartPoint.CustomerPoint.Y;
                double BBY = BoardList[i].BottomLine.StartPoint.CustomerPoint.Y;
                Boolean epfpF = BoardList[i].BoardCode.Equals("epBoard") || BoardList[i].BoardCode.Equals("fpBoard");
                if (epfpF)
                {
                    BLX = BoardList[i].OverheadLine.StartPoint.CustomerPoint.X;
                    BRX = BoardList[i].OverheadLine.EndPoint.CustomerPoint.X;
                }
                else
                {
                    BLX = BoardList[i].BottomLine.StartPoint.CustomerPoint.X;
                    BRX = BoardList[i].BottomLine.EndPoint.CustomerPoint.X;
                }
                for (int j = 0; j < BDList.Count; j++)
                {
                    Boolean F1 = BTY -0.2 <= BDList[j].HighY && BDList[j].HighY <= BTY + 0.2;
                    Boolean F2 = BBY -0.2 <= BDList[j].LowY && BDList[j].LowY <= BBY + 0.2;
                    //这种就是标注和实际识别出来的一样长
                    if (F1 && F2)
                        BoardList[i].DimensionThickList.Add(BDList[j]);
                    else
                    {
                        if (F1 && i + 1 < BNum)
                        {
                            Boolean F3 = BDList[j].LowY > BoardList[i + 1].BottomLine.StartPoint.CustomerPoint.Y;
                            if(F3)
                                BoardList[i].DimensionThickList.Add(BDList[j]);
                        }
                        if (F2 && i - 1 > 0)
                        {
                            Boolean F3 = BoardList[i - 1].OverheadLine.StartPoint.CustomerPoint.Y > BDList[j].HighY;
                            if(F3)
                                BoardList[i].DimensionThickList.Add(BDList[j]);
                        }
                    }
                }
            }
            for(int i = 0; i < BNum; i++)
            {
                Boolean epfpF = BoardList[i].BoardCode.Equals("epBoard") || BoardList[i].BoardCode.Equals("fpBoard");
                double refThink = BoardList[i].PlateThick;
                List<CAD_Dimension> tempDList = BoardList[i].DimensionThickList;
                if (tempDList.Count > 0)
                {
                    if (tempDList.Count == 1)
                        BoardList[i].DimensionPlateThick = tempDList[0].DimensionLength;
                    else
                    {
                        if (epfpF)
                        {
                            double MinDiffX = tempDList.Min(item => Math.Abs((double)item.X - BoardList[i].CusBCPoint.X));
                            List<CAD_Dimension> comDimensionList = tempDList.FindAll(item => 
                            Math.Abs((double)item.X - BoardList[i].CusBCPoint.X) == MinDiffX);
                            if(comDimensionList.Count == 1)
                                BoardList[i].DimensionPlateThick = comDimensionList[0].DimensionLength;
                            else
                            {
                                double colseDiff = comDimensionList.Min(item => Math.Abs(item.DimensionLength - refThink));
                                CAD_Dimension comDimension = comDimensionList.Find(item => Math.Abs(item.DimensionLength - refThink) 
                                == colseDiff);
                                BoardList[i].DimensionPlateThick = comDimension.DimensionLength;
                            }
                        }
                        else
                        {
                            double MaxDiffX = tempDList.Max(item => Math.Abs((double)item.X - BoardList[i].CusBCPoint.X));
                            List<CAD_Dimension> comDimensionList = tempDList.FindAll(item => 
                            Math.Abs((double)item.X - BoardList[i].CusBCPoint.X) == MaxDiffX);
                            if(comDimensionList.Count  == 1)
                                BoardList[i].DimensionPlateThick = comDimensionList[0].DimensionLength;
                            //长度最接近
                            else
                            {
                                double colseDiff = comDimensionList.Min(item => Math.Abs(item.DimensionLength - refThink));
                                CAD_Dimension comDimension = comDimensionList.Find(item => 
                                Math.Abs(item.DimensionLength - refThink) == colseDiff);
                                BoardList[i].DimensionPlateThick = comDimension.DimensionLength;
                            }
                        }
                    }
                }
            }
        }

        public static Dictionary<string, string> SetLayerColorInfo()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Dictionary<string, string> resDic = new Dictionary<string, string>();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                LayerTable layerTable = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead);
                foreach (ObjectId layerId in layerTable)
                {
                    LayerTableRecord layer = (LayerTableRecord)tr.GetObject(layerId, OpenMode.ForRead);
                    String layerName = layer.Name;
                    String layerColor = layer.Color.ColorIndex.ToString();
                    resDic.Add(layerName, layerColor);
                }
                tr.Commit();
            }
            return resDic;
        }

        public static void SetLineColorByLayerColor(List<MixedCAD_Line> CadLineList)
        {
            Dictionary<string, string> layerColorDic = SetLayerColorInfo();
            List<string> layerColorKeys = layerColorDic.Keys.ToList();
            int colorNum = layerColorKeys.Count();
            if(colorNum > 0)
            {
                for(int i = 0; i < CadLineList.Count; i++)
                {
                    String layerName = CadLineList[i].LayerName;
                    String displayName = CadLineList[i].ColorInfo.ColorNameForDisplay;
                    if (displayName.Equals("BYLAYER"))
                        if(layerColorKeys.Contains(layerName))
                            CadLineList[i].ColorInfo.ColorIndex = layerColorDic[layerName];
                }
            }
        }

        //Merge UI Show Data About Fangtie 
        public static void MergeUIFangtieSameWidthData()
        {
            List<BoardSectionItem> UIList = new List<BoardSectionItem>();
            List<BoardSectionItem> AList = AssemblyShareData.ASectionList;
            List<BoardSectionItem> AFList = AList.FindAll(item => item.BoardCode.Equals("fangtie"));
            List<BoardSectionItem> ANFList = AList.FindAll(item => !item.BoardCode.Equals("fangtie"));
            ANFList.ForEach(item => item.PlateWidth = Math.Round(item.PlateWidth, 1));
            if (AFList.Count > 0)
            {
                BoardSectionItem OriginFItem = (BoardSectionItem)AFList[0].Clone();
                HashSet<double> FWidthSet = new HashSet<double>();
                AFList.ForEach(item => FWidthSet.Add(item.PlateWidth));
                if (FWidthSet.Count > 0)
                {
                    List<double> FWidthList = FWidthSet.ToList();
                    List<BoardSectionItem> TShowFList = new List<BoardSectionItem>();
                    if(FWidthList.Count > 1)
                    {
                        for(int i = 0; i < FWidthList.Count; i++)
                        {
                            double tempW = FWidthList[i];
                            int targetFWIndex = AFList.FindIndex(item => item.PlateWidth == tempW);
                            if(targetFWIndex != -1)
                            {
                                BoardSectionItem ShowFItem = (BoardSectionItem)AFList[targetFWIndex].Clone();
                                List<BoardSectionItem> SameWFList = AFList.FindAll(item => item.PlateWidth == tempW).ToList();
                                if (SameWFList.Count > 0)
                                {
                                    ShowFItem.Num = SameWFList.Count;
                                    List<string> FBUIDList = SameWFList.Select(item => item.BoardUID).ToList();
                                    string tempFUID = string.Join("-", FBUIDList);
                                    ShowFItem.BoardUID = tempFUID;
                                    TShowFList.Add(ShowFItem);
                                }
                            }
                        }
                    }
                    else
                    {
                        BoardSectionItem ShowFItem = (BoardSectionItem)OriginFItem.Clone();
                        double targetW = FWidthList.First();
                        List<BoardSectionItem> SameWFList = AFList.FindAll(item => item.PlateWidth == targetW).ToList();
                        if (SameWFList.Count > 0)
                        {
                            ShowFItem.Num = SameWFList.Count;
                            List<string> FBUIDList = SameWFList.Select(item => item.BoardUID).ToList();
                            string tempFUID = string.Join("-", FBUIDList);
                            ShowFItem.BoardUID = tempFUID;
                            TShowFList.Add(ShowFItem);
                        }
                    }

                    if (TShowFList.Count > 0)
                        AFList = TShowFList;
                }
            }
            if (AFList.Count > 0)
                UIList.AddRange(AFList);
            if (ANFList.Count > 0)
                UIList.AddRange(ANFList);
            if(UIList.Count > 0)
                UIList = UIList.OrderBy(item => item.plateLineNo).ToList();
            
            //Fangtie Same Name
            if(UIList.Count > 0)
            {
                for (int i = 0; i < UIList.Count; i++)
                {
                    int FBIndex = UIList.FindIndex(item => item.BoardCode.Equals(UIList[i].BoardCode));
                    UIList[i].BoardName = CU.SetBoardNameByCode(UIList[i].BoardCode);
                    if (i - FBIndex > 0)
                        UIList[i].BoardName += (i - FBIndex);
                }
            AssemblyShareData.AUIBlueSectionList = UIList;
            }

        }

        public static void IdentificationAllLogic(List<MixedCAD_Line> TVList, List<MixedCAD_Circle> TVCirList, AssemViewCADInfo AVInfo)
        {
            List<MixedCAD_Line> AVList = AVInfo.AVLList;
            List<MixedCAD_Line> tvCheckTLineList = TVList.FindAll(item => item.LineType == CADLineType.XDirLine);
            List<MixedCAD_Line> avCheckTLineList = AVList.FindAll(item => item.LineType == CADLineType.XDirLine);
            Boolean DepF = TVAndAssemViewTLineDep(tvCheckTLineList, avCheckTLineList);
            if (!DepF)
            {
                if (AVList.Count > 0)
                    AVList = AVList.FindAll(item => item.LineType != CADLineType.NONE).ToList();
                List<MixedCAD_Line> ACLList = AVInfo.ACLList;
                List<CAD_Dimension> ADimList = AVInfo.ADimList;
                List<MixedCAD_Text> ATextList = AVInfo.ATextList;
                List<MixedCAD_Arc> AArcList = AVInfo.AArcList;
                List<MixedCAD_Circle> ACirList = AVInfo.ACirList;
                List<MixedCAD_Line> ATranPolyList = AVInfo.ATranPolyLList;
                List<MixedCAD_Curve> ACurvelist = AVInfo.ACurvelist;
                //SetLineColorByLayerColor(AVList);
                AssAddAuxInfo auxInfo =  CU.GetAssAddAuxInfo();
                ColProInfo compleLList = CU.CATLineAllocStrategy(AVList, ACLList, auxInfo);
                AssemblyShareData.ASectionList = TBLineCandidateAlgorithm(compleLList.CandidateTLineList);
                if (AssemblyShareData.ASectionList.Count > 0)
                {
                    AssemblyShareData.ASectionList.ForEach(item => item.PlateLength = MoldBaseShare.Length);
                    AssemblyShareData.ASectionList[0].PlateWidth = Math.Round(AssemblyShareData.ASectionList[0].OverheadLine.RealLength, 0);
                }

                //After the board is identified, the data is sorted out due to the conversion of the middle coordinates
                ComputedUtils.CalAssemblyRefCenterPoint(AssemblyShareData.ASectionList);

                //Begin Compare TV AV Center Point
                ComputedUtils.CompareCustomerDWGABSCoor();

                ComputedUtils.CalAllAssemblySplitCoor(AVInfo);

                Boolean CoorF = AssemblyShareData.avtvAbsCCoorF;

                ComputedUtils.CalAssemblyBoardRefCoorInfo();

                //if (!CoorF)
                //{
                //    //Calculate the coordinates of the total quantity
                //    //ComputedUtils.CalAllAssemblySplitCoor(AVInfo);

                //    //Calculate AssemblyShareData.ASectionList Coordinates
                //    ComputedUtils.CalAssemblyBoardRefCoorInfo();
                //}

                // Set PullingSize Ref Scope 
                CU.SetPullingParamScope();

                SetFangtieInfo(compleLList.AVLineYDic, compleLList.OBLineYDic, ACLList);
                
                CU.SetHoleParamScope(MoldBaseShare.Width, MoldBaseShare.Length);
            
                //Set ASectionList UID & Name & Board Center Coor 
                SetABListUIDAndCenter();

                if (ADimList.Count > 0)
                    SetBoardDimensionInfo(ADimList);
               SetBoardSteel(ATextList);
               List<AralinPrimions> APList = CU.PALConCircles(ACirList, AArcList, ATextList);
               SetHanging(APList);

               ComputedUtils.TranAssemblyColProInfo(compleLList);
                SetEPFPBoardWidth(TVList, TVCirList);

                Dictionary<CircleKey, List<MixedCAD_Circle>> tempallConCirDic = CU.ProcessConCircles(TVCirList);
               List<ConSpeCircle> tempConSpeList = CU.SameCirDicTransToConSpe(tempallConCirDic);
               CU.SetCirDicPosType(tempConSpeList);
               CU.Step1_BlurHCAppoint(tempConSpeList);

               //Rec Top View Item & Hole
               ProcessTopViewHole();
               RItemProcess(compleLList.ItemTSLineYDic, compleLList.AVLineYDic, compleLList.OBLineYDic, 
                   AArcList,ATranPolyList, ACLList, ACurvelist);
               //Compare Item  HoleSplit DB Standard
               DeduceHolePitchIsStandard();
               MergeUIFangtieSameWidthData();
               AutoTypeCRUIAfterRecognizeEvent(RenderType.AfterRecognize);
               CallMenuShow();
               ATypeDwgRemarkLabel(auxInfo, TVList);
            }
            else
                MessageBox.Show("投影图组装图框选操作存在重复图元信息 请正确操作!");
        }

        //About Label
        public static void ATypeDwgRemarkLabel(AssAddAuxInfo auxInfo, List<MixedCAD_Line> TVList)
        {
            try
            {
                //string fontPath = CADAuxiliaryUtils.FindFitSysFontPath();
                //CADAuxiliaryUtils.CreateDXTextStyle(fontPath);
                DWGVObjectIdInfo IdInfo = new DWGVObjectIdInfo();
                //DWGVObjectIdInfo IdInfo = CADAuxiliaryUtils.GetDefineIdInfo();
                ATypeDrawTVCruxLabel(IdInfo.AVObjectId, TVList, auxInfo.IShapedF);
                CADAuxiliaryUtils.ATypeDrawTVScrewHoleLabel(IdInfo);
                ATypeDrawAssemblyViewCruxLabel(IdInfo.AVObjectId);
                CADAuxiliaryUtils.ATypeDrawAssemBoardThickLabel(IdInfo.AVObjectId);
                ATypeDrawAssemSPGPRPLabel(IdInfo.AVObjectId);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        //TBLine Collection Candidate interval screening algorithm 
        public static List<BoardSectionItem> TBLineCandidateAlgorithm(List<FullInfoLine> OriginList)
        {
            SpcialAssemType assmeType = SpcialAssemType.Normal;
            //UI Ref Board Info
            List<BoardSectionItem> TargetList = (List<BoardSectionItem>)ConvertUtils.DeepCopyObject(AssemblyShareData.ASectionList);
            int FirstFIndex = TargetList.FindIndex(item => item.BoardCode.Equals("fangtie"));
            //Fangtie Airborne
            double fangtieAirborne = 0.0;
            //Airborne
            double NowAirborneValue = 0;
            double defaultAirborneValue = 10;
            List<BoardSectionItem> CollectionDataList = new List<BoardSectionItem>();
            //Judge assemType
            int hrLastIndex = AssemblyShareData.ASectionList.FindLastIndex(item => item.BoardCode.Equals("hrBoard"));
            int bpFirstIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("bpBoard"));
            Boolean spcialF = hrLastIndex + 1 == bpFirstIndex;
            if (spcialF)
                assmeType = SpcialAssemType.hrOverbp;

            //上方铁 sfangtie(横摆) 热流道板 hrBoard 垫板 mpBoard 暂不考虑
            if (FirstFIndex != -1)
            {
                int LastFIndex = TargetList.FindLastIndex(item => item.BoardCode.Equals("fangtie"));
                //Fangtie Take Two Apart Match
                if (LastFIndex != -1)
                {
                    List<BoardSectionItem> UpFList = TargetList.GetRange(0, FirstFIndex);
                    List<BoardSectionItem> DownFList = TargetList.GetRange(LastFIndex + 1, TargetList.Count - (LastFIndex + 1));
                    //先匹配方铁以下(底板和上下针板)
                    if (DownFList.Count > 0)
                    {
                        //线段倒过来匹配
                        List<FullInfoLine> DList = new List<FullInfoLine>(OriginList);
                        DList.Reverse();
                        DownFList = DownFList.OrderByDescending(item => item.plateLineNo).ToList();
                        for (int i = 0; i < DList.Count - 1; i++)
                        {
                            int j = i + 1;
                            if (DownFList.Count > 0)
                            {
                                //No Airborne
                                if (!(Math.Abs(DList[i].StartPoint.CustomerPoint.Y - DList[j].StartPoint.CustomerPoint.Y) <= defaultAirborneValue))
                                {
                                    BoardSectionItem SItem = new BoardSectionItem();
                                    SItem.BoardCode = DownFList.First().BoardCode;
                                    SItem.PlateThick = Math.Abs(Math.Round(DList[i].StartPoint.CustomerPoint.Y - DList[j].StartPoint.CustomerPoint.Y, 2));
                                    //For ep fp
                                    SItem.boardLRBoundInfo.BoardLX = DList[j].StartPoint.CustomerPoint.X;
                                    SItem.boardLRBoundInfo.BoardRX = DList[j].EndPoint.CustomerPoint.X;
                                    SItem.PlateWidth = Math.Round(DList[j].RealLength, 0);
                                    SItem.OverheadLine = DList[j];
                                    SItem.BottomLine = DList[i];
                                    SItem.plateLineNo = DownFList.First().plateLineNo;
                                    SItem.OverAirborneValue = NowAirborneValue;
                                    SItem.ReFlag = true;
                                    NowAirborneValue = 0;
                                    CollectionDataList.Add(SItem);
                                    DownFList.Remove(DownFList.First());
                                }
                            }
                        }
                    }

                    //match Board Over Fangtie
                    if (UpFList.Count > 0)
                    {
                        //线段倒过来匹配
                        List<FullInfoLine> UList = new List<FullInfoLine>(OriginList);
                        int fpBoardIndex = CollectionDataList.FindIndex(item => item.BoardCode.Equals("fpBoard"));
                        if (fpBoardIndex != -1)
                        {
                            //排除精框线长度和针板线 长度一致 造成误判的场景
                            double epfpBoardWidth = CollectionDataList[fpBoardIndex].PlateWidth;
                            UList = UList.FindAll(item => !(Math.Round(epfpBoardWidth, 0) <= Math.Round(item.RealLength, 0) &&
                                Math.Round(item.RealLength, 0) <= Math.Round(epfpBoardWidth, 0) + 6)).ToList();
                        }
                        for (int i = 0; i < UList.Count - 1; i++)
                        {
                            int j = i + 1;
                            if (UpFList.Count > 0)
                            {
                                //处理 隔热板 hsBoard
                                //从头到尾 match
                                if (UpFList.First().BoardCode.Equals("hsBoard"))
                                {
                                    BoardSectionItem SItem = new BoardSectionItem();
                                    SItem.BoardCode = UpFList.First().BoardCode;
                                    SItem.PlateThick = Math.Abs(Math.Round(UList[i].StartPoint.CustomerPoint.Y - UList[j].StartPoint.CustomerPoint.Y, 2));
                                    SItem.PlateWidth = Math.Round(UList[j].RealLength, 0);
                                    SItem.boardLRBoundInfo.BoardLX = UList[j].StartPoint.CustomerPoint.X;
                                    SItem.boardLRBoundInfo.BoardRX = UList[j].EndPoint.CustomerPoint.X;
                                    SItem.OverheadLine = UList[i];
                                    SItem.BottomLine = UList[j];
                                    SItem.plateLineNo = UpFList.First().plateLineNo;
                                    SItem.ReFlag = true;
                                    CollectionDataList.Add(SItem);
                                    //if Match Remove First
                                    UpFList.Remove(UpFList.First());
                                }
                                else
                                {
                                    //不离空 set 10
                                    if (!(Math.Abs(UList[i].StartPoint.CustomerPoint.Y - UList[j].StartPoint.CustomerPoint.Y) <= defaultAirborneValue))
                                    {
                                        BoardSectionItem SItem = new BoardSectionItem();
                                        SItem.BoardCode = UpFList.First().BoardCode;
                                        SItem.PlateThick = Math.Abs(Math.Round(UList[i].StartPoint.CustomerPoint.Y - UList[j].StartPoint.CustomerPoint.Y, 2));
                                        SItem.PlateWidth = Math.Round(UList[j].RealLength, 0);
                                        SItem.boardLRBoundInfo.BoardLX = UList[j].StartPoint.CustomerPoint.X;
                                        SItem.boardLRBoundInfo.BoardRX = UList[j].EndPoint.CustomerPoint.X;
                                        SItem.OverheadLine = UList[i];
                                        SItem.BottomLine = UList[j];
                                        SItem.plateLineNo = UpFList.First().plateLineNo;
                                        SItem.OverAirborneValue = NowAirborneValue;
                                        NowAirborneValue = 0;
                                        SItem.ReFlag = true;
                                        CollectionDataList.Add(SItem);
                                        UpFList.Remove(UpFList.First());
                                    }
                                    else
                                    {
                                        double MayBeAirborneValue = Math.Abs(UList[i].StartPoint.CustomerPoint.Y - UList[j].StartPoint.CustomerPoint.Y);
                                        if (MayBeAirborneValue > 0)
                                            NowAirborneValue = MayBeAirborneValue;
                                    }
                                }
                            }
                        }
                    }
                }

                CollectionDataList = CollectionDataList.OrderBy(item => item.plateLineNo).ToList();
                //单独设置方铁
                List<BoardSectionItem> AllfangtieList = TargetList.FindAll(item => item.BoardCode.Equals("fangtie"));
                if (AllfangtieList.Count > 0)
                {
                    BoardSectionItem OriginFirstFBoard = TargetList[FirstFIndex];
                    int FCount = AllfangtieList.Count;

                    int startFBIndex = -1;
                    int endFBIndex = -1;
                    if (assmeType == SpcialAssemType.Normal)
                    {
                        startFBIndex = FirstFIndex - 1;
                        endFBIndex = CollectionDataList.Count - 1;
                    }
                    if (assmeType == SpcialAssemType.hrOverbp)
                    {
                        startFBIndex = FirstFIndex - 1;
                        endFBIndex = hrLastIndex - 1;
                    }

                    for (int i = 0; i < FCount; i++)
                    {
                        BoardSectionItem PerF = CollectionDataList[startFBIndex];
                        BoardSectionItem bpF = CollectionDataList[endFBIndex];
                        BoardSectionItem fangtieItem = new BoardSectionItem();
                        fangtieItem.OverheadLine = PerF.BottomLine;
                        fangtieItem.BottomLine = bpF.OverheadLine;
                        fangtieItem.BoardCode = AllfangtieList[i].BoardCode;
                        fangtieItem.BoardName = AllfangtieList[i].BoardName;
                        fangtieItem.plateLineNo = OriginFirstFBoard.plateLineNo;
                        fangtieItem.Num = OriginFirstFBoard.Num;
                        fangtieItem.ReFlag = true;
                        //方铁宽度 暂时无法计算 需要借助竖线
                        fangtieItem.PlateThick = Math.Round(Math.Abs(fangtieItem.OverheadLine.StartPoint.CustomerPoint.Y -
                            fangtieItem.BottomLine.StartPoint.CustomerPoint.Y), 2) - fangtieAirborne;
                        fangtieItem.OverAirborneValue = fangtieAirborne;
                        CollectionDataList.Insert(FirstFIndex + i, fangtieItem);
                    }
                }
            }
            //走无方铁逻辑 
            else
            {
                for (int i = 0; i < OriginList.Count - 1; i++)
                {
                    int j = i + 1;
                    if (TargetList.Count > 0)
                    {
                        //从头到尾 match 处理 隔热板 hsBoard
                        if (TargetList.First().BoardCode.Equals("hsBoard"))
                        {
                            BoardSectionItem SItem = new BoardSectionItem();
                            SItem.BoardCode = TargetList.First().BoardCode;
                            SItem.PlateThick = Math.Abs(Math.Round(OriginList[i].StartPoint.CustomerPoint.Y - OriginList[j].StartPoint.CustomerPoint.Y, 2));
                            SItem.boardLRBoundInfo.BoardLX = OriginList[j].StartPoint.CustomerPoint.X;
                            SItem.boardLRBoundInfo.BoardRX = OriginList[j].EndPoint.CustomerPoint.X;
                            SItem.PlateWidth = Math.Round(OriginList[j].RealLength, 0);
                            SItem.OverheadLine = OriginList[i];
                            SItem.BottomLine = OriginList[j];
                            SItem.plateLineNo = TargetList.First().plateLineNo;
                            SItem.ReFlag = true;
                            CollectionDataList.Add(SItem);
                            //Match And remove First
                            TargetList.Remove(TargetList.First());
                        }
                        else
                        {
                            //不离空 set 10
                            if (!(Math.Abs(OriginList[i].StartPoint.CustomerPoint.Y - OriginList[j].StartPoint.CustomerPoint.Y) <= defaultAirborneValue))
                            {
                                BoardSectionItem SItem = new BoardSectionItem();
                                SItem.BoardCode = TargetList.First().BoardCode;
                                SItem.PlateThick = Math.Abs(Math.Round(OriginList[i].StartPoint.CustomerPoint.Y - OriginList[j].StartPoint.CustomerPoint.Y, 2));
                                SItem.PlateWidth = Math.Round(OriginList[j].RealLength, 0);
                                SItem.boardLRBoundInfo.BoardLX = OriginList[i].StartPoint.CustomerPoint.X;
                                SItem.boardLRBoundInfo.BoardRX = OriginList[i].EndPoint.CustomerPoint.X;
                                SItem.OverheadLine = OriginList[i];
                                SItem.BottomLine = OriginList[j];
                                SItem.plateLineNo = TargetList.First().plateLineNo;
                                SItem.OverAirborneValue = NowAirborneValue;
                                NowAirborneValue = 0;
                                SItem.ReFlag = true;
                                CollectionDataList.Add(SItem);
                                TargetList.Remove(TargetList.First());
                            }
                            else
                            {
                                double MayBeAirborneValue = Math.Abs(OriginList[i].StartPoint.CustomerPoint.Y - OriginList[j].StartPoint.CustomerPoint.Y);
                                if (MayBeAirborneValue > 0)
                                    NowAirborneValue = MayBeAirborneValue;
                            }
                        }
                    }

                }
            }

            //设置相对A板位置关系
            int MayBeaBoardIndex = CollectionDataList.FindIndex(item => item.BoardCode.Equals("aBoard"));
            //设置a板作为 全局板宽
            if (MayBeaBoardIndex != -1)
            {
                double aBoardMinWidth = CollectionDataList.FindAll(item => item.BoardCode.Equals("aBoard")).Min(item => item.PlateWidth);
                MoldBaseShare.Width = CollectionDataList.Find(item => item.BoardCode.Equals("aBoard") && item.PlateWidth == aBoardMinWidth).PlateWidth;
            }
            int AutoaBoardIndex = CollectionDataList.FindIndex(item => item.BoardCode.Equals("aBoard"));
            if (AutoaBoardIndex != -1)
            {
                //设置各块板相对于A板的位置关系
                for (int i = 0; i < CollectionDataList.Count; i++)
                {
                    if (i <= AutoaBoardIndex)
                        CollectionDataList[i].withaBoardPosType = UnloadMoldPosType.aBoardUp;
                    else
                        CollectionDataList[i].withaBoardPosType = UnloadMoldPosType.aBoardDown;
                }
            }
            CollectionDataList = CollectionDataList.OrderBy(item => item.plateLineNo).ToList();
            //底板的前一块板 以上板线为准
            if(CollectionDataList.Count >= 2)
                CollectionDataList[CollectionDataList.Count - 2].PlateWidth = CollectionDataList[CollectionDataList.Count - 2].OverheadLine.RealLength;

            List<BoardSectionItem> sfangtieList = AssemblyShareData.AUIBlueSectionList.FindAll(item => item.BoardCode.Equals("sfangtie")).ToList();
            if(sfangtieList.Count > 0)
            {
                for(int i = 0; i < sfangtieList.Count; i++)
                {
                    string tempTargetBoardCode = sfangtieList[i].BoardCode;
                    for(int j = 0; j < CollectionDataList.Count; j++)
                    {
                        string tempBoardCode = CollectionDataList[j].BoardCode;
                        if (tempTargetBoardCode.Equals(tempBoardCode))
                            CollectionDataList[j].Num = sfangtieList[i].Num;
                    }
                }
            }
            return CollectionDataList;
        }

        public static void SetABListUIDAndCenter()
        {
            List<BoardSectionItem> ASectionList = AssemblyShareData.ASectionList;
            if (ASectionList.Count > 0)
            {
                for (int i = 0; i < ASectionList.Count; i++)
                {
                    ASectionList[i].BoardName = CU.SetBoardNameByCode(ASectionList[i].BoardCode);
                    int FBIndex = ASectionList.FindIndex(item => item.BoardCode.Equals(ASectionList[i].BoardCode));
                    ASectionList[i].BoardUID = ASectionList[i].BoardCode + (i - FBIndex);
                    //设置Z0
                    Boolean FF = ASectionList[i].BoardCode.Equals("fangtie");
                    if (FF)
                    {
                        ASectionList[i].extraFInfo.RelFBCPoint.Y = ASectionList[i].OverheadLine.StartPoint.CustomerPoint.Y - ASectionList[i].PlateThick / 2;
                        int BeforeFIndex = ASectionList.FindIndex(item => item.BoardCode.Equals("fangtie"));
                        double BeforeFCX = ASectionList[BeforeFIndex - 1].CusBCPoint.X;
                        ASectionList[i].CusBCPoint.Y = ASectionList[i].OverheadLine.StartPoint.CustomerPoint.Y - ASectionList[i].PlateThick / 2;
                        ASectionList[i].ProBCPoint.X = Math.Round(ASectionList[i].extraFInfo.RelFBCPoint.X - BeforeFCX,2);
                        ASectionList[i].ProBCPoint.Z = Math.Round(ASectionList[i].CusBCPoint.Y - ASectionList[0].OverheadLine.StartPoint.CustomerPoint.Y,2);
                    }
                    else
                    {
                        double LX = ASectionList[i].BottomLine.StartPoint.CustomerPoint.X;
                        double RX = ASectionList[i].BottomLine.EndPoint.CustomerPoint.X;
                        ASectionList[i].CusBCPoint.X = (LX + RX) / 2;
                        ASectionList[i].CusBCPoint.Y = ASectionList[i].OverheadLine.StartPoint.CustomerPoint.Y - ASectionList[i].PlateThick / 2;
                        ASectionList[i].ProBCPoint.Z = Math.Round(ASectionList[i].CusBCPoint.Y - ASectionList[0].OverheadLine.StartPoint.CustomerPoint.Y,2);
                    }
                }

                //非标+板 if同一件板名称 需要+序号
                if (ASectionList.Count > 1)
                {
                    for (int i = 1; i < ASectionList.Count; i++)
                    {
                        List<BoardSectionItem> bnQueueList = new List<BoardSectionItem>();
                        bnQueueList = ASectionList.GetRange(0, i);
                        int lastIndex = bnQueueList.FindLastIndex(item => item.BoardCode.Equals(ASectionList[i].BoardCode));
                        if(lastIndex != -1)
                        {
                            List<BoardSectionItem> allSanemList = bnQueueList.FindAll(item => item.BoardCode.Equals(ASectionList[i].BoardCode));
                            if (allSanemList.Count > 0)
                                ASectionList[i].BoardName = CU.SetBoardNameByCode(ASectionList[i].BoardCode) + allSanemList.Count();
                        }
                    }
                }
            }
        }

        //收集投影图圆的混合信息 用于过滤 后续组装图组成横板线需要排除的横线段
        public static List<MixedHoleInfo> CollectionMixHoleInfo()
        {
            List<MixedHoleInfo> MixHoleInfoList = new List<MixedHoleInfo>();
            List<string> CircleKeysList = WholeTopViewData.CircleDic.Keys.ToList();
            for(int i = 0; i < CircleKeysList.Count; i++)
            {
                List<ConSpeCircle> tempCircleList = WholeTopViewData.CircleDic[CircleKeysList[i]];
                if(tempCircleList.Count > 0)
                {
                    MixedHoleInfo tempInfo = new MixedHoleInfo();
                    for (int j = 0; j < tempCircleList.Count; j++)
                    {
                        if (j == 0)
                        {
                            tempInfo.CenterPoint.CustomerPoint.X = tempCircleList[j].CustomerConHPoint.X;
                            tempInfo.CenterPoint.CustomerPoint.Y = tempCircleList[j].CustomerConHPoint.X;
                        }
                        tempInfo.DimList.AddRange(tempCircleList[j].DimList);
                    }
                    MixHoleInfoList.Add(tempInfo);
                }
            }
            return MixHoleInfoList;
        }

        public static void ClearOldCoaTagData()
        {
            CoaGraHoleTagData.CoaReturnPinCList = new List<HoleGroupTag>();
            CoaGraHoleTagData.CoaSPScrewCList = new List<HoleGroupTag>();
            CoaGraHoleTagData.CoaGPScrewCList = new List<HoleGroupTag>();
            CoaGraHoleTagData.CoaFallerScrewCList = new List<HoleGroupTag>();
            CoaGraHoleTagData.CoaBigScrewCList = new List<HoleGroupTag>();
            CoaGraHoleTagData.CoaSmallScrewCList = new List<HoleGroupTag>();
        }

        public static void ProcessTopViewHole()
        {
            //Clear
            ClearOldCoaTagData();
            // Pitch By Fangtie
            if (FangtieShareData.HasLRF)
                WholeTopViewData.CircleDic = GroupGraHoleIfExitF();
            List<string> CircleKeysList = WholeTopViewData.CircleDic.Keys.ToList();
            for (int i = 0; i < CircleKeysList.Count; i++)
            {
                List<ConSpeCircle> tempList = WholeTopViewData.CircleDic[CircleKeysList[i]];
                if(tempList.Count > 0)
                    CU.Step1_CoaGraCollectHole(tempList);
            }
            CU.Step2_RPWiderRangeSort();
            CU.Step2_GPWiderRangeSort();
            CU.Step3_GroupByStandCoor();
            //Sort and classify witch Group Hole Belong to witch Item 
            CU.TidyUpCoaData();
            //Set Tag All Arg 
            CU.DRPartOfHoleArg();
            //Set Candidate Item Hole Arg By Tag
            CU.SetItemHoleDataByTag();
            CU.TransCoaTigSplitCoorLogic();
        }

        //TO EDIT
        public static Dictionary<string, List<ConSpeCircle>> GroupGraHoleIfExitF()
        {
            Dictionary<string, List<ConSpeCircle>> ResDic = new Dictionary<string, List<ConSpeCircle>>();
            List<string> kList = WholeTopViewData.CircleDic.Keys.ToList();
            if(FangtieShareData.FLXInfo.CustomerX != null && FangtieShareData.FRXInfo.CustomerX != null)
            {
                double FLXInfo = (double)FangtieShareData.FLXInfo.SplitX;
                double FRXInfo = (double)FangtieShareData.FRXInfo.SplitX;
                for (int i = 0; i < kList.Count; i++)
                {
                    List<ConSpeCircle> tempList = WholeTopViewData.CircleDic[kList[i]];
                    //List<ConSpeCircle> groupLR = tempList.FindAll(item => item.CustomerConHPoint.X < FLXInfo || item.CustomerConHPoint.X > FRXInfo);
                    //List<ConSpeCircle> groupC = tempList.FindAll(item => FLXInfo < item.CustomerConHPoint.X && item.CustomerConHPoint.X < FRXInfo);

                    List<ConSpeCircle> groupLR = tempList.FindAll(item => item.ConRefPoint.X < FLXInfo || item.ConRefPoint.X > FRXInfo);
                    List<ConSpeCircle> groupC = tempList.FindAll(item => FLXInfo < item.ConRefPoint.X && item.ConRefPoint.X < FRXInfo);

                    string keyLR = kList[i] + "LR";
                    string keyC = kList[i] + "C";
                    ResDic.Add(keyLR, groupLR);
                    ResDic.Add(keyC, groupC);
                }
            }
            //过滤空数据
            if (ResDic.Count > 0)
            {
                List<string> tempKeys = ResDic.Keys.ToList();
                for (int i = 0; i < tempKeys.Count; i++)
                {
                    Boolean KeyF = ResDic.ContainsKey(tempKeys[i]);
                    if (KeyF)
                    {
                        List<ConSpeCircle> tempList = ResDic[tempKeys[i]];
                        if (tempList.Count == 0)
                            ResDic.Remove(tempKeys[i]);
                    }
                }
            }
            return ResDic;
        }



        //Identification Item Process
        public static void RItemProcess(Dictionary<double, List<MixedCAD_Line>> ItemTSLineYDic, Dictionary<double, List<MixedCAD_Line>> AVLineYDic,
            Dictionary<double, List<MixedCAD_Line>> OBLineYDic,List<MixedCAD_Arc> AArcList,List<MixedCAD_Line> ATranPolyList, 
            List<MixedCAD_Line> ACLList,List<MixedCAD_Curve> ACurvelist)
        {
            Boolean fpBoardExit = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("fpBoard")) != -1;
            Boolean epBoardExit = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("epBoard")) != -1;
            Boolean fangtieExit = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("fangtie")) != -1;
            Boolean tpBoardExit = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("tpBoard")) != -1;

            //GP Bush End Pos BoardIndex 
            int GPBushEndBoardIndex = -1;

            if (tpBoardExit)
                RecognizeTopPanelScrew(AVLineYDic, OBLineYDic);

            if (fpBoardExit && epBoardExit)
            {
                RecognizeFallerScrew("PLANA", AVLineYDic, ACLList);
                Boolean NOEPFPF = ShareItemData.ItemList.FindIndex(item => item.ItemNameType == DItemNameType.PinBoardScrew) == -1;
                if (NOEPFPF)
                    RecognizeFallerScrew("PLANB", AVLineYDic, ACLList);
            }

            RecognizeBpScrew(AVLineYDic, OBLineYDic);

            //有方铁 识别方铁螺丝 无方铁 识别工字螺丝(和方铁螺丝同种规格的螺丝)
            //方铁螺丝or公制螺丝 牙位置的板 作为 GPBushEndBoardIndex 下标
            if (fangtieExit)
            {
                GPBushEndBoardIndex = RecognizeFangtieScrew("PLANA", AVLineYDic, OBLineYDic, ACLList);
                if(GPBushEndBoardIndex == -1)
                    GPBushEndBoardIndex = RecognizeFangtieScrew("PLANB", AVLineYDic, OBLineYDic, ACLList);
            }
            else
                GPBushEndBoardIndex = RecognizeFGenericScrew(AVLineYDic, OBLineYDic);

            if (epBoardExit)
            {
                RecognizeBottomRPItem("PLANA", AVLineYDic, OBLineYDic, ACurvelist, ACLList);
                Boolean NORPF = ShareItemData.ItemList.FindIndex(item => item.ItemNameType == DItemNameType.ReturnPin) == -1;
                if (NORPF)
                    RecognizeBottomRPItem("PLANB", AVLineYDic, OBLineYDic, ACurvelist, ACLList);
            }

            if (CADCommonForm.MoldTypeStr.Equals("PP"))
                RecognizeSP(ItemTSLineYDic, AVLineYDic, AArcList, ATranPolyList);

            RecognizeGP(GPBushEndBoardIndex,ItemTSLineYDic, AVLineYDic, AArcList, ACurvelist);

            RecognizeEGP(AVLineYDic, AArcList);

            //Add Sort Info for UI Show 
            List<SingleItem> tempOperList = ShareItemData.ItemList;
            if (tempOperList.Count > 0)
            {
                for (int i = 0; i < tempOperList.Count; i++)
                {
                    tempOperList[i].SortNo = CU.SetSortByItemNameType(tempOperList[i].ItemNameType);
                    tempOperList[i].lineNo = i;
                }
            }

            //Merge Item lineNo with their Bush(SP/GP)
            for (int i = 0; i < tempOperList.Count; i++)
            {
                Boolean bushF = tempOperList[i].ItemCode.Contains("Bush");
                if (bushF)
                {
                    Boolean GPF = tempOperList[i].ItemCode.Contains("Guide");
                    Boolean SPF = tempOperList[i].ItemCode.Contains("Support");
                    if (GPF)
                    {
                        double refAVX = tempOperList[i].AssembleCenterPointX;
                        List<SingleItem> gpOperList = tempOperList.FindAll(item => !item.ItemCode.Contains("Bush") && item.ItemCode.Contains("Guide"));
                        int targetIndex = gpOperList.FindIndex(item => item.AssembleCenterPointX == refAVX);
                        tempOperList[i].lineNo = gpOperList[targetIndex].lineNo;
                    }
                    if (SPF)
                    {
                        double refAVX = tempOperList[i].AssembleCenterPointX;
                        List<SingleItem> spOperList = tempOperList.FindAll(item => !item.ItemCode.Contains("Bush") && item.ItemCode.Contains("Support"));
                        int targetIndex = spOperList.FindIndex(item => item.AssembleCenterPointX == refAVX);
                        tempOperList[i].lineNo = spOperList[targetIndex].lineNo;
                    }
                }
            }

            dataForm.gpRevCheckBox.Checked = ShareItemBoardShipInfo.extraShipInfo.gpRevFlag;
            dataForm.gpOverSpCheckBox.Checked = ShareItemBoardShipInfo.extraShipInfo.gpOverSpFlag;
            dataForm.rpOverSpCheckBox.Checked = ShareItemBoardShipInfo.extraShipInfo.rpOverSpFlag;
            ShareItemData.ItemList = ShareItemData.ItemList.OrderBy(item => item.SortNo).ToList();
            ShareItemData.ItemList.ForEach(item => item.ItemName = CU.SetItemNameByType(item.ItemNameType));

            //Set UID
            if (ShareItemData.ItemList.Count > 0)
                for (int i = 0; i < ShareItemData.ItemList.Count; i++)
                    ShareItemData.ItemList[i].ItemUID = ShareItemData.ItemList[i].ItemCode + i;

            ShareItemData.UIItemList = (List<SingleItem>)ConvertUtils.DeepCopy(ShareItemData.ItemList);
            CompareNoRecognizeItem();
        }

        //对比标准 零件 显示未识别的零件
        public static void CompareNoRecognizeItem()
        {
            try
            {
                List<LabourSingleItem> SurplusList = new List<LabourSingleItem>();
                string CategoryStr = CADCommonForm.CategoryStr;
                List<StandardSeriesRelItem> allCompareItemCorList = ParamsConfigData.StandardBoardRelItemList
                    .FindAll(item => item.MouldSeries.Equals(CategoryStr)).ToList();
                Boolean exitEGPF = ShareItemData.ItemList.FindIndex(item => item.ItemCode.Equals("EGPPin")) != -1;
                
                if (allCompareItemCorList.Count > 0)
                {
                    List<LabourSingleItem> diffList = allCompareItemCorList.Select(p => new LabourSingleItem
                    {
                        ItemCode = p.ItemCode,
                        ItemName = p.ItemName,
                        ItemNum = p.ItemNum,
                        ItemRemark = p.ItemRemark
                    }).ToList();
                    if (diffList.Count > 0)
                        diffList = diffList.Distinct(new MergeCompareItemComparer()).ToList();
                    if (diffList.Count > 0)
                    {
                        for (int i = 0; i < diffList.Count; i++)
                        {
                            Boolean nohasF = ShareItemData.ItemList.FindIndex(item => 
                            item.ItemName.Equals(diffList[i].ItemName)) == -1;
                            if (nohasF)
                                SurplusList.Add(diffList[i]);
                        }
                    }
                    if (!exitEGPF)
                    {
                        List<ScrewHole> egpSList = HoleCandidateShareData.EGPScrewCList;
                        if (egpSList.Count > 0)
                        {
                            List<LabourSingleItem> labourEGPList = new List<LabourSingleItem>();
                            List<LabourSingleItem> labourEGPBushList = new List<LabourSingleItem>();
                            List<double> egpDimList = egpSList.Select(item => item.Dim).Distinct().ToList();
                            if (egpDimList.Count > 0)
                            {
                                for (int i = 0; i < egpDimList.Count; i++)
                                {
                                    List<ScrewHole> tempegpList = egpSList.FindAll(item => item.Dim == egpDimList[i]);
                                    if(tempegpList.Count > 0)
                                    {
                                        LabourSingleItem tempItem = new LabourSingleItem();
                                        tempItem.ItemCode = "EGPPin";
                                        tempItem.ItemNameType = DItemNameType.EGPPin;
                                        tempItem.ItemName = "中托边";
                                        tempItem.ItemDim = egpDimList[i];
                                        int tempegpNum = tempegpList.Count;
                                        tempItem.ItemNum = tempegpNum;
                                        labourEGPList.Add(tempItem);
                                    }
                                }
                            }
                            if(labourEGPList.Count > 0)
                            {
                                Boolean fpExitF = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("fpBoard")) != -1;
                                Boolean epExitF = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("epBoard")) != -1;
                                if(epExitF || fpExitF)
                                {
                                    for(int i = 0; i < labourEGPList.Count; i++)
                                    {
                                        LabourSingleItem tempItem = new LabourSingleItem();
                                        tempItem.ItemCode = "EGPBush";
                                        tempItem.ItemName = "中托司";
                                        tempItem.ItemNameType = DItemNameType.EGPBush;
                                        tempItem.ItemRemark = "EGPBush";
                                        tempItem.ItemDim = labourEGPList[i].ItemDim;
                                        tempItem.ItemNum = labourEGPList[i].ItemNum;
                                        labourEGPBushList.Add(tempItem);
                                    }
                                }
                            }

                            if (labourEGPList.Count > 0)
                                SurplusList.AddRange(labourEGPList);
                            if(labourEGPBushList.Count > 0)
                                SurplusList.AddRange(labourEGPBushList);
                        }
                    }

                    //Set UID & ItemNameType
                    if (SurplusList.Count > 0)
                    {
                        //Filter No Necessary Item
                        SurplusList = FilterNeedRepItem(SurplusList);
                        for (int i = 0; i < SurplusList.Count; i++)
                        {
                            SurplusList[i].ItemUID = SurplusList[i].ItemName + i;
                            SurplusList[i].ItemNameType = ComputedUtils.SetItemNameTypeByCode(SurplusList[i].ItemCode);
                        }
                        //Process About Not Nozzle
                        RemoveSPAnOtherNameItem(SurplusList);
                        ShareItemData.SurplusItemList = SurplusList;
                        ReplenishLabourItemParam();
                        ShareItemData.UISurplusItemList = (List<LabourSingleItem>)ConvertUtils.DeepCopyObject(SurplusList);
                    }
                }
            }
            catch (Exception ex)
            {
                
            }

        }

        public static List<LabourSingleItem> FilterNeedRepItem(List<LabourSingleItem> ItemList)
        {
            List<LabourSingleItem> resList =  (List<LabourSingleItem>)ConvertUtils.DeepCopyObject(ItemList);
            Boolean fangtieF = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("fangtie")) != -1;
            Boolean epF = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("epBoard")) != -1;
            Boolean fpF = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("fpBoard")) != -1;
            List<string> epfpGroup = new List<string>() { "PinBoardScrew", "ReturnPin", "ReturnPinScrew" };
            Boolean epfpF = epF && fpF;
            if (!epfpF)
                resList = resList.FindAll(item => !epfpGroup.Contains(item.ItemCode));
            if (!fangtieF)
                resList = resList.FindAll(item => !item.ItemCode.Equals("SpaceBlockScrew"));
            if(!epfpF && !fangtieF)
            {
                LabourSingleItem tempItem = new LabourSingleItem();
                tempItem.ItemCode = "GenericScrew";
                tempItem.ItemNameType = DItemNameType.GenericScrew;
                tempItem.ItemName = "公制螺丝";
                tempItem.ItemRemark = "";
                resList = resList.FindAll(item => !item.ItemCode.Equals("BottomPanelScrew"));
                resList.Add(tempItem);
            }
            if(resList.Count > 0)
            {
                int spIndex = resList.FindIndex(item => item.ItemCode.Equals("SupportPin") 
                || item.ItemCode.Equals("NoNozzleMesonSupportPin"));
                if(spIndex != -1)
                {
                    LabourSingleItem tempItem1 = new LabourSingleItem();
                    tempItem1.ItemCode = "Meson";
                    tempItem1.ItemNameType = DItemNameType.Meson;
                    tempItem1.ItemName = "水口介子";
                    tempItem1.ItemRemark = "";
                    LabourSingleItem tempItem2 = new LabourSingleItem();
                    tempItem2.ItemCode = "MesonScrew";
                    tempItem2.ItemNameType = DItemNameType.MesonScrew;
                    tempItem2.ItemName = "介子螺丝";
                    tempItem2.ItemRemark = "";
                    resList.Add(tempItem1);
                    resList.Add(tempItem2);
                }
            }
            return resList;
        }

        public static void RemoveSPAnOtherNameItem(List<LabourSingleItem> ItemList)
        {
            //导柱(无介子)
            Boolean NMSPF = ShareItemData.UIItemList.FindIndex(item => item.ItemNameType == 
            DItemNameType.NoNozzleMesonSupportPin) != -1;
            if(NMSPF)
            {
                int labourSPindex = ItemList.FindIndex(item => item.ItemNameType == 
                DItemNameType.SupportPin);
                if (labourSPindex != -1)
                    ItemList.RemoveAt(labourSPindex);
            }
            //A套(导柱无介子)
            Boolean NMSPABushF = ShareItemData.UIItemList.FindIndex(item => item.ItemNameType == 
            DItemNameType.NoNozzleMesonSupportPinABush) != -1;
            if (NMSPABushF)
            {
                int labourSPABushindex = ItemList.FindIndex(item => item.ItemNameType == 
                DItemNameType.SupportPinABush);
                if (labourSPABushindex != -1)
                    ItemList.RemoveAt(labourSPABushindex);
            }
            //B套(导柱无介子)
            Boolean NMSPBBushF = ShareItemData.UIItemList.FindIndex(item => item.ItemNameType == 
            DItemNameType.NoNozzleMesonSupportPinBBush) != -1;
            if (NMSPBBushF)
            {
                int labourSPBBushindex = ItemList.FindIndex(item => item.ItemNameType == 
                DItemNameType.SupportPinBBush);
                if (labourSPBBushindex != -1)
                    ItemList.RemoveAt(labourSPBBushindex);
            }
        }

        //补充 未识别零件 规格参数(长度及Dim)
        public static void ReplenishLabourItemParam()
        {
            string NowMoldSize = ComputedUtils.ATypeGetMoldSizeFormat();
            int nearSize = ComputedUtils.GetMNearMoldSize(NowMoldSize);
            string CommonMouldSeries = "通用";
            string MouldSeries = null;
            if (CADCommonForm.MoldTypeStr.Equals("PP"))
                MouldSeries = "细水口";
            if (CADCommonForm.MoldTypeStr.Equals("SG"))
                MouldSeries = "大水口";
            if (CADCommonForm.MoldTypeStr.Equals("TP"))
                MouldSeries = "简化型";
            List<StandardHoleData> DBSHList = ParamsConfigData.MoldHoleList.FindAll(item =>
             item.MouldSize == nearSize &&
             (item.MouldSeries.Equals(CommonMouldSeries) || item.MouldSeries.Equals(MouldSeries)));
            //从标准拿 Dim Num
            if (nearSize != -1)
            {
                if (ShareItemData.SurplusItemList.Count > 0)
                {
                    int bpSIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("BottomPanelScrew"));
                    if (bpSIndex != -1)
                    {
                        int SNum = DBSHList.FindAll(item => item.Item.Equals("小螺丝")).Count;
                        int bpBoardIndex = AssemblyShareData.ASectionList.FindLastIndex(item => item.BoardCode.Equals("bpBoard"));
                        if (bpBoardIndex != -1)
                        {
                            Boolean KF = ParamsConfigData.RecommendDimDic.ContainsKey("底板螺丝");
                            if (KF)
                            {
                                double bpsDim = ParamsConfigData.RecommendDimDic["底板螺丝"];
                                ShareItemData.SurplusItemList[bpSIndex].ItemDim = bpsDim;
                                ShareItemData.SurplusItemList[bpSIndex].ItemNum = SNum;
                            }
                        }
                    }

                    int tpSIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("TopPanelScrew"));
                    if (tpSIndex != -1)
                    {
                        int tpBoardIndex = AssemblyShareData.ASectionList.FindLastIndex(item => item.BoardCode.Equals("tpBoard"));
                        if (tpBoardIndex != -1)
                        {
                            Boolean KF = ParamsConfigData.RecommendDimDic.ContainsKey("面板螺丝");
                            if (KF)
                            {
                                int SNum = DBSHList.FindAll(item => item.Item.Equals("大螺丝")).Count;
                                double tpsDim = ParamsConfigData.RecommendDimDic["面板螺丝"];
                                ShareItemData.SurplusItemList[tpSIndex].ItemDim = tpsDim;
                                ShareItemData.SurplusItemList[tpSIndex].ItemNum = SNum;
                            }
                        }
                    }

                    int fSIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("SpaceBlockScrew"));
                    if (fSIndex != -1)
                    {
                        Boolean fangtieExit = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("fangtie")) != -1;
                        if (fangtieExit)
                        {
                            List<BoardSectionItem> NoFallerBoardList = AssemblyShareData.ASectionList.FindAll(item => !item.BoardCode.Equals("epBoard") 
                            && !item.BoardCode.Equals("fpBoard"));
                            int fIndex = NoFallerBoardList.FindLastIndex(item => item.BoardCode.Equals("fangtie"));
                            Boolean KF = ParamsConfigData.RecommendDimDic.ContainsKey("方铁螺丝");
                            if (KF)
                            {
                                double fDim = ParamsConfigData.RecommendDimDic["方铁螺丝"];
                                int SNum = DBSHList.FindAll(item => item.Item.Equals("大螺丝")).Count;
                                ShareItemData.SurplusItemList[fSIndex].ItemDim = fDim;
                                ShareItemData.SurplusItemList[fSIndex].ItemNum = SNum;
                            }
                        }
                        else
                        {
                            //公制螺丝 不好推 默认底板和底板的上一块板
                            if (AssemblyShareData.ASectionList.Count >= 2)
                            {
                                Boolean KF = ParamsConfigData.RecommendDimDic.ContainsKey("公制螺丝");
                                if (KF)
                                {
                                    double fDim = ParamsConfigData.RecommendDimDic["公制螺丝"];
                                    int SNum = DBSHList.FindAll(item => item.Item.Equals("大螺丝")).Count;
                                    ShareItemData.SurplusItemList[fSIndex].ItemDim = fDim;
                                    ShareItemData.SurplusItemList[fSIndex].ItemDim = SNum;
                                }
                            }
                        }
                    }

                    int pbSIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("PinBoardScrew"));
                    if (pbSIndex != -1)
                    {
                        Boolean KF = ParamsConfigData.RecommendDimDic.ContainsKey("针板螺丝");
                        if (KF)
                        {
                            double tpsDim = ParamsConfigData.RecommendDimDic["针板螺丝"];
                            int SNum = DBSHList.FindAll(item => item.Item.Equals("针板螺丝")).Count;
                            ShareItemData.SurplusItemList[pbSIndex].ItemDim = tpsDim;
                            if (SNum != 0)
                                ShareItemData.SurplusItemList[pbSIndex].ItemNum = SNum;
                        }
                    }

                    int rpIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("ReturnPin"));
                    if (rpIndex != -1)
                    {
                        Boolean KF = ParamsConfigData.RecommendDimDic.ContainsKey("回针");
                        if (KF)
                        {
                            double rpDim = ParamsConfigData.RecommendDimDic["回针"];
                            int SNum = DBSHList.FindAll(item => item.Item.Equals("回针")).Count;
                             ShareItemData.SurplusItemList[rpIndex].ItemDim = rpDim;
                            if (SNum != 0)
                                ShareItemData.SurplusItemList[rpIndex].ItemNum = SNum;
                        }
                    }

                    int gpIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("GuidePin"));
                    if (gpIndex != -1)
                    {
                        Boolean gpF = ParamsConfigData.RecommendDimDic.ContainsKey("导柱");
                        if (gpF)
                        {
                            double gpDim = ParamsConfigData.RecommendDimDic["导柱"];

                            int SNum = DBSHList.FindAll(item => item.Item.Equals("导柱")).Count;
                            ShareItemData.SurplusItemList[gpIndex].ItemDim = gpDim;
                            ShareItemData.SurplusItemList[gpIndex].ItemNum = SNum;
                        }
                    }

                    int gsIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("GenericScrew"));
                    if(gsIndex != -1)
                    {
                        Boolean KF = ParamsConfigData.RecommendDimDic.ContainsKey("方铁螺丝");
                        if (KF)
                        {
                            double fDim = ParamsConfigData.RecommendDimDic["方铁螺丝"];
                            int SNum = DBSHList.FindAll(item => item.Item.Equals("大螺丝")).Count;
                            ShareItemData.SurplusItemList[fSIndex].ItemDim = fDim;
                            ShareItemData.SurplusItemList[fSIndex].ItemDim = SNum;
                        }
                    }

                    int spIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("SupportPin")
                    ||item.ItemCode.Equals("NoNozzleMesonSupportPin"));
                    if (spIndex != -1 && CADCommonForm.MoldTypeStr.Equals("PP"))
                    {
                        Boolean spF = ParamsConfigData.RecommendDimDic.ContainsKey("拉杆");
                        if (spF)
                        {
                            double spDim = ParamsConfigData.RecommendDimDic["拉杆"];
                            int SNum = DBSHList.FindAll(item => item.Item.Equals("拉杆")).Count;
                            ShareItemData.SurplusItemList[spIndex].ItemDim = spDim;
                            ShareItemData.SurplusItemList[spIndex].ItemNum = SNum;
                            int spMesonIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("Meson"));
                            int spMesonScrewIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("MesonScrew"));
                            if(spMesonIndex != -1)
                            {
                                SingleItem MesonItem = RepMesonSpe(spDim);
                                ShareItemData.SurplusItemList[spMesonIndex].ItemDim = MesonItem.Dim;
                                ShareItemData.SurplusItemList[spMesonIndex].ItemNum = SNum;
                                ShareItemData.SurplusItemList[spMesonIndex].ItemL = MesonItem.RealH;
                            }
                            if(spMesonScrewIndex != -1)
                            {
                                SingleItem MesonItem = RepMesonScrewSpe(spDim);
                                ShareItemData.SurplusItemList[spMesonScrewIndex].ItemDim = MesonItem.Dim;
                                ShareItemData.SurplusItemList[spMesonScrewIndex].ItemNum = SNum;
                                ShareItemData.SurplusItemList[spMesonScrewIndex].ItemL = MesonItem.RealH;

                            }
                        }
                    }

                    List<LabourSingleItem> bushSList = ShareItemData.SurplusItemList.FindAll(item => item.ItemCode.Contains("Bush")).ToList();
                    if(bushSList.Count > 0)
                    {
                        for(int i = 0; i < bushSList.Count; i++)
                        {
                            string targetUID = bushSList[i].ItemUID;
                            int tempIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemUID.Equals(targetUID));
                            if(tempIndex != -1)
                            {
                                string tempItemCode = ShareItemData.SurplusItemList[tempIndex].ItemCode;
                                Boolean GPBushF = tempItemCode.Contains("Guide");
                                Boolean SPBushF = tempItemCode.Contains("Support");
                                if (GPBushF)
                                {
                                    Boolean gpF = ParamsConfigData.RecommendDimDic.ContainsKey("导柱");
                                    if (gpF)
                                    {
                                        double gpDim = ParamsConfigData.RecommendDimDic["导柱"];
                                        int SNum = DBSHList.FindAll(item => item.Item.Equals("导柱")).Count;
                                        ShareItemData.SurplusItemList[tempIndex].ItemDim = gpDim;
                                        ShareItemData.SurplusItemList[tempIndex].ItemNum = SNum;
                                    }
                                }
                                if (SPBushF)
                                {
                                    Boolean spF = ParamsConfigData.RecommendDimDic.ContainsKey("拉杆");
                                    if (spF)
                                    {
                                        double gpDim = ParamsConfigData.RecommendDimDic["拉杆"];
                                        int SNum = DBSHList.FindAll(item => item.Item.Equals("拉杆")).Count;
                                        ShareItemData.SurplusItemList[tempIndex].ItemDim = gpDim;
                                        ShareItemData.SurplusItemList[tempIndex].ItemNum = SNum;
                                    }
                                }
                            }
                        }
                    }

                    //大水口
                    if (CADCommonForm.MoldTypeStr.Equals("SG"))
                    {
                        //A套(导柱)厚度 = 推板
                        int GuideABushIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("GuideABush")
                        && item.ItemRemark.Equals("推板"));
                        if (GuideABushIndex != -1)
                        {
                            int stBoardIndex = AssemblyShareData.ASectionList.FindLastIndex(item => item.BoardCode.Equals("stBoard"));
                            if (stBoardIndex != -1)
                                ShareItemData.SurplusItemList[GuideABushIndex].ItemL = AssemblyShareData.ASectionList[stBoardIndex].PlateThick;
                            Boolean gpF = ParamsConfigData.RecommendDimDic.ContainsKey("A套(导柱)");
                            if (gpF)
                            {
                                int SNum = DBSHList.FindAll(item => item.Item.Equals("导柱")).Count;
                                double gpDim = ParamsConfigData.RecommendDimDic["A套(导柱)"];
                                ShareItemData.SurplusItemList[GuideABushIndex].ItemDim = gpDim;
                                ShareItemData.SurplusItemList[GuideABushIndex].ItemNum = SNum;
                            }
                        }
                        //B套(导柱)厚度 = A板
                        int GuideBBushIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("GuideBBush")
                        && item.ItemRemark.Equals("A板"));
                        if (GuideBBushIndex != -1)
                        {
                            int AutoaBoardIndex = AssemblyShareData.ASectionList.FindLastIndex(item => item.BoardCode.Equals("aBoard"));
                            if (AutoaBoardIndex != -1)
                                ShareItemData.SurplusItemList[GuideBBushIndex].ItemL = AssemblyShareData.ASectionList[AutoaBoardIndex].PlateThick;
                            Boolean gpF = ParamsConfigData.RecommendDimDic.ContainsKey("B套(导柱)");
                            if (gpF)
                            {
                                int SNum = DBSHList.FindAll(item => item.Item.Equals("导柱")).Count;
                                double gpDim = ParamsConfigData.RecommendDimDic["B套(导柱)"];
                                ShareItemData.SurplusItemList[GuideBBushIndex].ItemDim = gpDim;
                                ShareItemData.SurplusItemList[GuideBBushIndex].ItemNum = SNum;
                            }
                        }
                    }

                    //简化型 
                    if (CADCommonForm.MoldTypeStr.Equals("TP"))
                    {
                        //B套(导柱)厚度 = A板
                        int GuideBBushIndex1 = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("GuideBBush")
                        && item.ItemRemark.Equals("A板"));
                        if (GuideBBushIndex1 != -1)
                        {
                            Boolean gpF1 = ParamsConfigData.RecommendDimDic.ContainsKey("B套(导柱)");
                            if (gpF1)
                            {
                                int SNum = DBSHList.FindAll(item => item.Item.Equals("导柱")).Count;
                                double gpDim1 = ParamsConfigData.RecommendDimDic["B套(导柱)"];
                                ShareItemData.SurplusItemList[GuideBBushIndex1].ItemDim = gpDim1;
                                ShareItemData.SurplusItemList[GuideBBushIndex1].ItemNum = SNum;
                            }
                        }
                        //B套(导柱)厚度 = B板
                        int GuideBBushIndex2 = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("GuideBBush") 
                        && item.ItemRemark.Equals("B板"));
                        if (GuideBBushIndex2 != -1)
                        {
                            Boolean gpF2 = ParamsConfigData.RecommendDimDic.ContainsKey("B套(导柱)");
                            if (gpF2)
                            {
                                int SNum = DBSHList.FindAll(item => item.Item.Equals("导柱")).Count;
                                double gpDim2 = ParamsConfigData.RecommendDimDic["B套(导柱)"];
                                ShareItemData.SurplusItemList[GuideBBushIndex2].ItemDim = gpDim2;
                                ShareItemData.SurplusItemList[GuideBBushIndex2].ItemNum = SNum;
                            }
                        }
                        //A套(导柱)厚度 = 水口推板
                        int GuideABushIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("GuideABush") 
                        && item.ItemRemark.Equals("水口推板"));
                        if (GuideABushIndex != -1)
                        {
                            Boolean gpF = ParamsConfigData.RecommendDimDic.ContainsKey("A套(导柱)");
                            if (gpF)
                            {
                                int SNum = DBSHList.FindAll(item => item.Item.Equals("导柱")).Count;
                                double gpDim = ParamsConfigData.RecommendDimDic["A套(导柱)"];
                                ShareItemData.SurplusItemList[GuideABushIndex].ItemDim = gpDim;
                                ShareItemData.SurplusItemList[GuideABushIndex].ItemNum = SNum;
                            }
                        }
                    }

                    //细水口
                    if (CADCommonForm.MoldTypeStr.Equals("PP"))
                    {
                        // 拉杆 A套 水口推板
                        int SupportPinABushIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("SupportPinABush") 
                        && item.ItemRemark.Equals("水口推板"));
                        if (SupportPinABushIndex != -1)
                        {
                            Boolean gpF = ParamsConfigData.RecommendDimDic.ContainsKey("A套(拉杆)");
                            if (gpF)
                            {
                                int SNum = DBSHList.FindAll(item => item.Item.Equals("拉杆")).Count;
                                double gpDim = ParamsConfigData.RecommendDimDic["A套(拉杆)"];
                                ShareItemData.SurplusItemList[SupportPinABushIndex].ItemDim = gpDim;
                                ShareItemData.SurplusItemList[SupportPinABushIndex].ItemNum = SNum;
                            }
                        }
                        // 拉杆 B套 A板
                        int SupportPinBBushIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("SupportPinBBush") 
                        && item.ItemRemark.Equals("A板"));
                        if (SupportPinBBushIndex != -1)
                        {
                            Boolean gpF = ParamsConfigData.RecommendDimDic.ContainsKey("A套(拉杆)");
                            if (gpF)
                            {
                                int SNum = DBSHList.FindAll(item => item.Item.Equals("拉杆")).Count;
                                double gpDim = ParamsConfigData.RecommendDimDic["A套(拉杆)"];
                                ShareItemData.SurplusItemList[SupportPinBBushIndex].ItemDim = gpDim;
                                ShareItemData.SurplusItemList[SupportPinBBushIndex].ItemNum = SNum;
                            }
                        }
                        //导柱 A套 推板
                        int GuideABushIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("GuideABush") 
                        && item.ItemRemark.Equals("推板"));
                        if (GuideABushIndex != -1)
                        {
                            Boolean gpF = ParamsConfigData.RecommendDimDic.ContainsKey("A套(导柱)");
                            if (gpF)
                            {
                                int SNum = DBSHList.FindAll(item => item.Item.Equals("导柱")).Count;
                                double gpDim = ParamsConfigData.RecommendDimDic["A套(导柱)"];
                                ShareItemData.SurplusItemList[GuideABushIndex].ItemDim = gpDim;
                                ShareItemData.SurplusItemList[GuideABushIndex].ItemNum = SNum;
                            }
                        }
                        //导柱 B套 A板
                        int GuideBBushIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("GuideBBush") 
                        && item.ItemRemark.Equals("A板"));
                        if (GuideBBushIndex != -1)
                        {
                            Boolean gpF = ParamsConfigData.RecommendDimDic.ContainsKey("B套(导柱)");
                            if (gpF)
                            {
                                int SNum = DBSHList.FindAll(item => item.Item.Equals("导柱")).Count;
                                double gpDim = ParamsConfigData.RecommendDimDic["B套(导柱)"];
                                ShareItemData.SurplusItemList[GuideBBushIndex].ItemDim = gpDim;
                                ShareItemData.SurplusItemList[GuideBBushIndex].ItemNum = SNum;
                            }
                        }
                    }

                }
            }

            //用识别出来的投影图孔标签去覆盖 Dim Num
            if (HoleCandidateShareData.BigScrewCList.Count > 0)
            {
                List<ScrewHole> targetList = HoleCandidateShareData.BigScrewCList;
                int tpSIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("TopPanelScrew"));
                if (tpSIndex != -1)
                {
                    ShareItemData.SurplusItemList[tpSIndex].ItemNum = targetList.Count;
                    ShareItemData.SurplusItemList[tpSIndex].ItemDim = targetList.First().Dim;
                }
                int fSIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("SpaceBlockScrew"));
                if (fSIndex != -1)
                {
                    List<ScrewHole> toAddHList = targetList.FindAll(item => FangtieShareData.FLXInfo.SplitX > item.CenterPoint.CustomerPoint.X
                    || item.CenterPoint.CustomerPoint.X > FangtieShareData.FRXInfo.SplitX).ToList();
                    if(toAddHList.Count > 0)
                    {
                        ShareItemData.SurplusItemList[fSIndex].ItemNum = toAddHList.Count;
                        ShareItemData.SurplusItemList[fSIndex].ItemDim = toAddHList.First().Dim;
                    }
                }
                int gsIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("GenericScrew"));
                if (gsIndex != -1)
                {
                    List<ScrewHole> toAddHList = targetList.FindAll(item => FangtieShareData.FLXInfo.SplitX > item.CenterPoint.CustomerPoint.X
                    || item.CenterPoint.CustomerPoint.X > FangtieShareData.FRXInfo.SplitX).ToList();
                    if (toAddHList.Count > 0)
                    {
                        ShareItemData.SurplusItemList[gsIndex].ItemNum = toAddHList.Count;
                        ShareItemData.SurplusItemList[gsIndex].ItemDim = toAddHList.First().Dim;
                    }
                }
            }
            if (HoleCandidateShareData.SmallScrewCList.Count > 0)
            {
                List<ScrewHole> targetList = new List<ScrewHole>();
                if (HoleCandidateShareData.SmallScrewCList.Count > 4)
                {
                    List<ScrewHole> bpSCList = HoleCandidateShareData.SmallScrewCList.FindAll(item => item.fPosType == FPosType.L || item.fPosType == FPosType.R).ToList();
                    targetList = bpSCList;
                }
                else
                    targetList = HoleCandidateShareData.SmallScrewCList;
                //底板螺丝
                int bpSIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("BottomPanelScrew"));
                if (bpSIndex != -1)
                {
                    ShareItemData.SurplusItemList[bpSIndex].ItemNum = targetList.Count;
                    ShareItemData.SurplusItemList[bpSIndex].ItemDim = targetList.First().Dim;
                }
            }
            if (HoleCandidateShareData.SPScrewCList.Count > 0)
            {
                List<ScrewHole> targetList = HoleCandidateShareData.SPScrewCList;
                int spIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("SupportPin"));
                if(spIndex != -1)
                {
                    ShareItemData.SurplusItemList[spIndex].ItemNum = targetList.Count;
                    ShareItemData.SurplusItemList[spIndex].ItemDim = targetList.First().Dim;
                }
                int nnmspIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("NoNozzleMesonSupportPin"));
                if (nnmspIndex != -1)
                {
                    ShareItemData.SurplusItemList[nnmspIndex].ItemNum = targetList.Count;
                    ShareItemData.SurplusItemList[nnmspIndex].ItemDim = targetList.First().Dim;
                }
                int SupportPinABushIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("SupportPinABush"));
                if (SupportPinABushIndex != -1)
                {
                    ShareItemData.SurplusItemList[SupportPinABushIndex].ItemNum = targetList.Count;
                    ShareItemData.SurplusItemList[SupportPinABushIndex].ItemDim = targetList.First().Dim;
                }
                int SupportPinBBushIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("SupportPinBBush"));
                if (SupportPinBBushIndex != -1)
                {
                    ShareItemData.SurplusItemList[SupportPinBBushIndex].ItemNum = targetList.Count;
                    ShareItemData.SurplusItemList[SupportPinBBushIndex].ItemDim = targetList.First().Dim;
                }
            }
            if (HoleCandidateShareData.GPScrewCList.Count > 0)
            {
                List<ScrewHole> targetList = HoleCandidateShareData.GPScrewCList;
                int gpIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("GuidePin"));
                if (gpIndex != -1)
                {
                    ShareItemData.SurplusItemList[gpIndex].ItemNum = targetList.Count;
                    ShareItemData.SurplusItemList[gpIndex].ItemDim = targetList.First().Dim;
                }
                int GuideABushIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("GuideABush"));
                if (GuideABushIndex != -1)
                {
                    ShareItemData.SurplusItemList[GuideABushIndex].ItemNum = targetList.Count;
                    ShareItemData.SurplusItemList[GuideABushIndex].ItemDim = targetList.First().Dim;
                }
                int GuideBBushIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("GuideBBush"));
                if (GuideBBushIndex != -1)
                {
                    ShareItemData.SurplusItemList[GuideBBushIndex].ItemNum = targetList.Count;
                    ShareItemData.SurplusItemList[GuideBBushIndex].ItemDim = targetList.First().Dim;
                }
            }
            if (HoleCandidateShareData.FallerScrewCList.Count > 0)
            {
                List<ScrewHole> targetList = HoleCandidateShareData.FallerScrewCList;
                int epfpIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("PinBoardScrew"));
                if (epfpIndex != -1)
                {
                    ShareItemData.SurplusItemList[epfpIndex].ItemNum = targetList.Count;
                    ShareItemData.SurplusItemList[epfpIndex].ItemDim = targetList.First().Dim;
                }
            }
            if (HoleCandidateShareData.ReturnPinCList.Count > 0)
            {
                List<ScrewHole> targetList = HoleCandidateShareData.ReturnPinCList;
                int rpIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("ReturnPin"));
                if (rpIndex != -1)
                {
                    ShareItemData.SurplusItemList[rpIndex].ItemNum = targetList.Count;
                    ShareItemData.SurplusItemList[rpIndex].ItemDim = targetList.First().Dim;
                }
            }

            //Rep Length
            if (ShareItemData.SurplusItemList.Count > 0)
            {
                //补充底板螺丝
                int bpSIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("BottomPanelScrew"));
                if (bpSIndex != -1)
                {
                    int SNum = DBSHList.FindAll(item => item.Item.Equals("小螺丝")).Count;
                    int bpBoardIndex = AssemblyShareData.ASectionList.FindLastIndex(item => item.BoardCode.Equals("bpBoard"));
                    if (bpBoardIndex != -1)
                    {
                        double ThroughPlateH = AssemblyShareData.ASectionList[bpBoardIndex].PlateThick;
                        Boolean KF = ParamsConfigData.RecommendDimDic.ContainsKey("底板螺丝");
                        if (KF)
                        {
                            double bpsDim = ParamsConfigData.RecommendDimDic["底板螺丝"];
                            if (bpsDim < 20)
                                ThroughPlateH += 5;
                            else
                                ThroughPlateH += 10;
                            ShareItemData.SurplusItemList[bpSIndex].ItemL = ThroughPlateH;
                        }
                    }
                }

                int gsIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("GenericScrew"));
                if(gsIndex != -1)
                {
                    double bpsDim = ShareItemData.SurplusItemList[gsIndex].ItemDim;
                    int lastIndex = AssemblyShareData.ASectionList.Count - 2;
                    if (lastIndex >= 0)
                    {
                        List<BoardSectionItem> tempBList = AssemblyShareData.ASectionList.GetRange(lastIndex, 2);
                        double ThroughPlateH = 0;
                        for (int i = 0; i < tempBList.Count; i++)
                            ThroughPlateH += tempBList[i].PlateThick;
                        if (bpsDim < 20)
                            ThroughPlateH += 5;
                        else
                            ThroughPlateH += 10;
                        ShareItemData.SurplusItemList[gsIndex].ItemL = ThroughPlateH;
                    }
                }

                //补充 面板螺丝
                int tpSIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("TopPanelScrew"));
                if (tpSIndex != -1)
                {
                    int tpBoardIndex = AssemblyShareData.ASectionList.FindLastIndex(item => item.BoardCode.Equals("tpBoard"));
                    if (tpBoardIndex != -1)
                    {
                        double ThroughPlateH = AssemblyShareData.ASectionList[tpBoardIndex].PlateThick;
                        Boolean KF = ParamsConfigData.RecommendDimDic.ContainsKey("面板螺丝");
                        if (KF)
                        {
                            int SNum = DBSHList.FindAll(item => item.Item.Equals("大螺丝")).Count;
                            double tpsDim = ParamsConfigData.RecommendDimDic["面板螺丝"];
                            if (tpsDim < 20)
                                ThroughPlateH += 5;
                            else
                                ThroughPlateH += 10;
                            ShareItemData.SurplusItemList[tpSIndex].ItemL = ThroughPlateH;
                        }
                    }
                }

                //补充 方铁螺丝
                int fSIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("SpaceBlockScrew"));
                if (fSIndex != -1)
                {
                    Boolean fangtieExit = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("fangtie")) != -1;
                    if (fangtieExit)
                    {
                        List<BoardSectionItem> TBList = new List<BoardSectionItem>();
                        int spBoardIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("spBoard"));
                        if(spBoardIndex != -1)
                        {
                            List<BoardSectionItem> NoFallerBoardList = AssemblyShareData.ASectionList.FindAll(item => !item.BoardCode.Equals("epBoard")
                            && !item.BoardCode.Equals("fpBoard"));
                            List<BoardSectionItem> nfList = NoFallerBoardList.FindAll(item => !item.BoardCode.Equals("fangtie"));
                            List<BoardSectionItem> fList = NoFallerBoardList.FindAll(item => item.BoardCode.Equals("fangtie"));
                            NoFallerBoardList = new List<BoardSectionItem>();
                            NoFallerBoardList.AddRange(nfList);
                            BoardSectionItem FFB = fList.First();
                            NoFallerBoardList.Add(FFB);
                            NoFallerBoardList = NoFallerBoardList.OrderBy(item => item.plateLineNo).ToList();
                            spBoardIndex = NoFallerBoardList.FindIndex(item => item.BoardCode.Equals("spBoard"));
                            spBoardIndex -= 1;
                            if (spBoardIndex != -1)
                                TBList = NoFallerBoardList.GetRange(spBoardIndex, NoFallerBoardList.Count - 1 - spBoardIndex + 1);
                        }
                        else
                        {
                            List<BoardSectionItem> NoFallerBoardList = AssemblyShareData.ASectionList.FindAll(item => !item.BoardCode.Equals("epBoard") 
                            && !item.BoardCode.Equals("fpBoard"));
                            int fIndex = NoFallerBoardList.FindLastIndex(item => item.BoardCode.Equals("fangtie"));
                            TBList = NoFallerBoardList.GetRange(fIndex, NoFallerBoardList.Count - 1 - fIndex + 1);
                        }

                        if (TBList.Count > 0)
                        {
                            double ThroughPlateH = 0;
                            for (int i = 0; i < TBList.Count; i++)
                                ThroughPlateH += TBList[i].PlateThick;
                            Boolean KF = ParamsConfigData.RecommendDimDic.ContainsKey("方铁螺丝");
                            if (KF)
                            {
                                double fDim = ParamsConfigData.RecommendDimDic["方铁螺丝"];
                                if (fDim < 20)
                                    ThroughPlateH += 5;
                                else
                                    ThroughPlateH += 10;
                                int SNum = DBSHList.FindAll(item => item.Item.Equals("大螺丝")).Count;
                                ShareItemData.SurplusItemList[fSIndex].ItemL = ThroughPlateH;
                            }
                        }
                    }
                    else
                    {
                        //公制螺丝 不好推 默认底板和底板的上一块板
                        if (AssemblyShareData.ASectionList.Count >= 2)
                        {
                            List<BoardSectionItem> TBList = AssemblyShareData.ASectionList.GetRange(AssemblyShareData.ASectionList.Count - 2, 2);
                            if (TBList.Count > 0)
                            {
                                double ThroughPlateH = 0;
                                for (int i = 0; i < TBList.Count; i++)
                                    ThroughPlateH += TBList[i].PlateThick;
                                Boolean KF = ParamsConfigData.RecommendDimDic.ContainsKey("公制螺丝");
                                if (KF)
                                {
                                    double fDim = ParamsConfigData.RecommendDimDic["公制螺丝"];
                                    if (fDim < 20)
                                        ThroughPlateH += 5;
                                    else
                                        ThroughPlateH += 10;
                                    int SNum = DBSHList.FindAll(item => item.Item.Equals("大螺丝")).Count;
                                    ShareItemData.SurplusItemList[fSIndex].ItemL = ThroughPlateH;
                                }
                            }
                        }
                    }
                }

                //补充 针板螺丝
                int pbSIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("PinBoardScrew"));
                if (pbSIndex != -1)
                {
                    int lepBoardIndex = AssemblyShareData.ASectionList.FindLastIndex(item => item.BoardCode.Equals("epBoard"));
                    if (lepBoardIndex != -1)
                    {
                        double ThroughPlateH = AssemblyShareData.ASectionList[lepBoardIndex].PlateThick;
                        Boolean KF = ParamsConfigData.RecommendDimDic.ContainsKey("针板螺丝");
                        if (KF)
                        {
                            double tpsDim = ParamsConfigData.RecommendDimDic["针板螺丝"];
                            if (tpsDim < 20)
                                ThroughPlateH += 5;
                            else
                                ThroughPlateH += 10;
                            int SNum = DBSHList.FindAll(item => item.Item.Equals("针板螺丝")).Count;
                            ShareItemData.SurplusItemList[pbSIndex].ItemL = ThroughPlateH;
                        }
                    }
                }

                //补充 回针
                int rpIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("ReturnPin"));
                if (rpIndex != -1)
                {
                    int fBIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("fangtie"));
                    int bBIndex = AssemblyShareData.ASectionList.FindLastIndex(item => item.BoardCode.Equals("bBoard"));
                    if (fBIndex != -1 && bBIndex != -1 && bBIndex < fBIndex)
                    {
                        //最后一块下针板
                        int epBIndex = AssemblyShareData.ASectionList.FindLastIndex(item => item.BoardCode.Equals("epBoard"));
                        if (epBIndex != -1)
                        {
                            List<BoardSectionItem> rpPBList = AssemblyShareData.ASectionList.GetRange(bBIndex, fBIndex - bBIndex + 1);
                            if (rpPBList.Count > 0)
                            {
                                double ThroughPlateH = 0;
                                for (int i = 0; i < rpPBList.Count; i++)
                                    ThroughPlateH += rpPBList[i].PlateThick;

                                ThroughPlateH -= AssemblyShareData.ASectionList[epBIndex].PlateThick;
                                Boolean KF = ParamsConfigData.RecommendDimDic.ContainsKey("回针");
                                if (KF)
                                {
                                    double rpDim = ParamsConfigData.RecommendDimDic["回针"];
                                    if (rpDim < 20)
                                        ThroughPlateH += 5;
                                    else
                                        ThroughPlateH += 10;
                                    if (ThroughPlateH > 0)
                                        ShareItemData.SurplusItemList[rpIndex].ItemL = ThroughPlateH;
                                }
                            }
                        }
                    }
                }

                //补充 导柱
                int gpIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("GuidePin"));
                if (gpIndex != -1)
                {
                    //非简化型 A板开始 B板结束
                    if (!CADCommonForm.MoldTypeStr.Equals("TP"))
                    {
                        int aBIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("aBoard"));
                        int bBIndex = AssemblyShareData.ASectionList.FindLastIndex(item => item.BoardCode.Equals("bBoard"));
                        if (aBIndex != -1 && bBIndex != -1 && bBIndex > aBIndex)
                        {
                            List<BoardSectionItem> abPBList = AssemblyShareData.ASectionList.GetRange(aBIndex, bBIndex - aBIndex + 1);
                            if (abPBList.Count > 0)
                            {
                                double ThroughPlateH = 0;
                                for (int i = 0; i < abPBList.Count; i++)
                                    ThroughPlateH += abPBList[i].PlateThick;
                                Boolean gpF = ParamsConfigData.RecommendDimDic.ContainsKey("导柱");
                                if (gpF)
                                {
                                    double gpDim = ParamsConfigData.RecommendDimDic["导柱"];
                                    if (ThroughPlateH > 0)
                                        ShareItemData.SurplusItemList[gpIndex].ItemL = ThroughPlateH;
                                }
                            }
                        }
                    }
                    //简化型 
                    else
                    {
                        //穿过的板 + 方铁的1/2
                        int fBIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("fangtie"));
                        if (fBIndex != -1)
                        {
                            List<BoardSectionItem> gpPBList = AssemblyShareData.ASectionList.GetRange(0, fBIndex);
                            if (gpPBList.Count > 0)
                            {
                                double ThroughPlateH = 0;
                                for (int i = 0; i < gpPBList.Count; i++)
                                {
                                    ThroughPlateH += gpPBList[i].OverAirborneValue;
                                    ThroughPlateH += gpPBList[i].PlateThick;
                                }
                                ThroughPlateH += AssemblyShareData.ASectionList[fBIndex].PlateThick / 2;
                                Boolean gpF = ParamsConfigData.RecommendDimDic.ContainsKey("导柱");
                                if (gpF)
                                {
                                    double gpDim = ParamsConfigData.RecommendDimDic["导柱"];
                                    if (ThroughPlateH > 0)
                                        ShareItemData.SurplusItemList[gpIndex].ItemL = ThroughPlateH;
                                }
                            }
                        }
                    }
                }

                //补充 拉杆
                int spIndex = ShareItemData.SurplusItemList.FindIndex(item => item.ItemCode.Equals("SupportPin")
                || item.ItemCode.Equals("NoNozzleMesonSupportPin"));
                if (spIndex != -1 && CADCommonForm.MoldTypeStr.Equals("PP"))
                {
                    //穿过的板 + 方铁的1/2
                    int fBIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("fangtie"));
                    if (fBIndex != -1)
                    {
                        List<BoardSectionItem> spPBList = AssemblyShareData.ASectionList.GetRange(0, fBIndex);
                        if (spPBList.Count > 0)
                        {
                            double ThroughPlateH = 0;
                            for (int i = 0; i < spPBList.Count; i++)
                            {
                                ThroughPlateH += spPBList[i].OverAirborneValue;
                                ThroughPlateH += spPBList[i].PlateThick;
                            }
                            ThroughPlateH += AssemblyShareData.ASectionList[fBIndex].PlateThick / 2;
                            Boolean gpF = ParamsConfigData.RecommendDimDic.ContainsKey("拉杆");
                            if (gpF)
                            {
                                double gpDim = ParamsConfigData.RecommendDimDic["拉杆"];
                                if (ThroughPlateH > 0)
                                    ShareItemData.SurplusItemList[spIndex].ItemL = ThroughPlateH;
                            }
                        }
                    }
                    else
                    {
                        double ThroughPlateH = 0;
                        List<BoardSectionItem> spPBList = AssemblyShareData.ASectionList.GetRange(0, AssemblyShareData.ASectionList.Count - 1);
                        BoardSectionItem LastB = AssemblyShareData.ASectionList[AssemblyShareData.ASectionList.Count - 1];
                        for (int i = 0; i < spPBList.Count; i++)
                        {
                            ThroughPlateH += spPBList[i].OverAirborneValue;
                            ThroughPlateH += spPBList[i].PlateThick;
                        }
                        ThroughPlateH += LastB.PlateThick / 2;
                        Boolean gpF = ParamsConfigData.RecommendDimDic.ContainsKey("拉杆");
                        if (gpF)
                        {
                            double gpDim = ParamsConfigData.RecommendDimDic["拉杆"];
                            if (ThroughPlateH > 0)
                                ShareItemData.SurplusItemList[spIndex].ItemL = ThroughPlateH;
                        }
                    }
                }

                //Rep EGP EGPBush
                List<LabourSingleItem> egpList = ShareItemData.SurplusItemList.FindAll(item => item.ItemCode.Equals("EGPPin"));
                if(egpList.Count > 0)
                {
                    for(int i = 0; i < egpList.Count; i++)
                    {
                        LabourSingleItem targetEGP = egpList[i];
                        int fIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("fangtie"));
                        if(fIndex != -1)
                        {
                            BoardSectionItem fBoard = AssemblyShareData.ASectionList[fIndex];
                            double overFY = fBoard.OverheadLine.StartPoint.CustomerPoint.Y;
                            int lastBIndex = AssemblyShareData.ASectionList.Count - 1;
                            if(lastBIndex > -1)
                            {
                                BoardSectionItem lastB = AssemblyShareData.ASectionList[lastBIndex];
                                double bootomY = lastB.BottomLine.StartPoint.CustomerPoint.Y;
                                double diffL = 5;
                                if (targetEGP.ItemDim >= 20)
                                    diffL = 10;
                                double BL = Math.Round(overFY - bootomY, 0);
                                targetEGP.ItemL = BL + diffL;
                            }
                        }
                    }
                }

                //For DB Remark Bush Length 
                List<LabourSingleItem> bushOperList = ShareItemData.SurplusItemList;
                double allepfpBThick = 0;
                List<BoardSectionItem> epBList = AssemblyShareData.ASectionList.FindAll(item => item.BoardCode.Equals("epBoard"));
                List<BoardSectionItem> fpBList = AssemblyShareData.ASectionList.FindAll(item => item.BoardCode.Equals("epBoard"));
                Boolean exitEPF = epBList.Count > 0;
                Boolean exitFPF = fpBList.Count > 0;
                if (exitEPF)
                    epBList.ForEach(item => allepfpBThick += item.PlateThick);
                if (exitFPF)
                    fpBList.ForEach(item => allepfpBThick += item.PlateThick);
                for (int i = 0; i < bushOperList.Count; i++)
                {
                    Boolean BushF = bushOperList[i].ItemCode.Contains("Bush");
                    if (BushF)
                    {
                        //By DB Remark
                        Boolean GPABushF = bushOperList[i].ItemCode.Contains("GuideABush");
                        Boolean GPBBushF = bushOperList[i].ItemCode.Contains("GuideBBush");
                        Boolean SPABushF = bushOperList[i].ItemCode.Contains("SupportPinABush");
                        Boolean SPBBushF = bushOperList[i].ItemCode.Contains("SupportPinBBush");
                        string remarkBCode = bushOperList[i].ItemRemark;
                        if (GPABushF || GPBBushF || SPABushF || SPBBushF)
                        {
                            int targetBoardIndex = AssemblyShareData.ASectionList.FindLastIndex(item => item.BoardCode.Equals(remarkBCode));
                            if(targetBoardIndex != -1)
                                bushOperList[i].ItemL = AssemblyShareData.ASectionList[targetBoardIndex].PlateThick;
                        }
                        if (bushOperList[i].ItemRemark.Equals("EGPBush"))
                        {
                            if(allepfpBThick != 0)
                            {
                                int TempTheoryH = Convert.ToInt32(allepfpBThick) - 5;
                                bushOperList[i].ItemL = CU.GPLessThan200TheoryLRepRule(TempTheoryH);
                            }
                        }

                    }
                }

            }
        }

        //Deduce every Item Hole Standard (除了很精确的判断出非标 其余都当标准)
        public static void DeduceHolePitchIsStandard()
        {
            Dictionary<string, Boolean> holeFinalDic = new Dictionary<string, bool>();
            //Has Be R 
            List<IHPSInfo> RItemPitchList = new List<IHPSInfo>();
            //In TV But No Be R (final Result)
            List<IHPSInfo> NRItemPitchList = new List<IHPSInfo>();
            //Has No In TV
            List<IHPSInfo> NinTVItemPitchList = new List<IHPSInfo>();
            List<IHPSInfo> dbAllCItemList = CU.GetdbAllItemMatchNameList();
            List<SingleItem> RItemList = (List<SingleItem>)ConvertUtils.DeepCopy(ShareItemData.ItemList);

            if (RItemList.Count > 0 && dbAllCItemList.Count > 0)
            {
                List<string> RStrList = RItemList.Select(item => item.ItemCode).ToList();
                List<string> DbAllStrList = dbAllCItemList.Select(item => item.ItemCode).ToList();
                List<string> NRStrList = DbAllStrList.Except(RStrList).ToList();
                if(NRStrList.Count > 0)
                    NRItemPitchList = dbAllCItemList.FindAll(item => NRStrList.Contains(item.ItemCode)).ToList();
            }

            //DB
            int NowMoldSize = int.Parse(MoldBaseShare.Width.ToString().Substring(0, 2) + MoldBaseShare.Length.ToString().Substring(0, 2));
            string CommonMouldSeries = "通用";
            string MouldSeries = null;
            if (CADCommonForm.MoldTypeStr.Equals("PP"))
                MouldSeries = "细水口";
            if (CADCommonForm.MoldTypeStr.Equals("SG"))
                MouldSeries = "大水口";
            if (CADCommonForm.MoldTypeStr.Equals("TP"))
                MouldSeries = "简化型";
            List<StandardHoleData> DBSHList = ParamsConfigData.MoldHoleList.FindAll(item =>
            item.MouldSize == NowMoldSize &&
            (item.MouldSeries.Equals(CommonMouldSeries) || item.MouldSeries.Equals(MouldSeries)));

            try
            {
                //Process R Item
                if (DBSHList.Count > 0)
                {
                    if (RItemList.Count > 0)
                        RItemList = RItemList.FindAll(item => item.ItemNameType != DItemNameType.EGPPin);
                    if (RItemList.Count > 0)
                        RItemList = RItemList.FindAll(item => item.ItemNameType != DItemNameType.EGPBush);
                    //Recognize With DB Pitch Condition
                    List<SHoleMatchCondition> MatchConditionList = new List<SHoleMatchCondition>();
                    Dictionary<string, HashSet<DItemNameType>> BoardHoleDic = new Dictionary<string, HashSet<DItemNameType>>();
                    for (int z = 0; z < RItemList.Count; z++)
                    {
                        string MatchItemName = RItemList[z].HSplitInfo.DBItemName;
                        int MathcDim = RItemList[z].HSplitInfo.DBDim;
                        List<StandardHoleData> DBItemCList = DBSHList.FindAll(item => item.Item.Equals(MatchItemName)).ToList();
                        if (DBItemCList.Count > 0)
                        {
                            //Need To Match Num 
                            RItemList[z].NeedMathHoleNum = DBItemCList.Count;
                            string targetUID = RItemList[z].ItemUID;
                            int siIndex = ShareItemData.ItemList.FindIndex(item => item.ItemUID.Equals(targetUID));
                            if(siIndex != -1)
                                ShareItemData.ItemList[siIndex].NeedMathHoleNum = DBItemCList.Count;
                            int CommomDim = RItemList[z].HSplitInfo.DBDim;
                            List<StandardHoleData> TSHList = RItemList[z].HSplitInfo.SplitInfoList;
                            if (TSHList.Count > 0)
                            {
                                for (int i = 0; i < TSHList.Count; i++)
                                {
                                    double ItemX = TSHList[i].ItemX;
                                    double ItemY = TSHList[i].ItemY;
                                    Boolean MathcF = DBItemCList.FindIndex(item => item.ItemX == TSHList[i].ItemX &&
                                    item.ItemY == TSHList[i].ItemY && item.ItemDim == CommomDim) != -1;
                                    if (MathcF)
                                        RItemList[z].ActMatchHoleNum += 1;
                                }
                            }
                            if (RItemList[z].NeedMathHoleNum != 0)
                            {
                                if (RItemList[z].NeedMathHoleNum == RItemList[z].ActMatchHoleNum)
                                    RItemList[z].HolePitchType = ItemHolesPitchType.SS;
                                else
                                    RItemList[z].HolePitchType = ItemHolesPitchType.NS;
                            }
                        }
                    }

                    //Process About Bush(DB Has No Bush)
                    if(RItemList.Count > 0)
                    {
                        List<SingleItem> BushRItemList = RItemList.FindAll(item => ConvertUtils.JudgeItemTypeAboutBush(item.ItemNameType));
                        List<SingleItem> NoBushRItemList = RItemList.FindAll(item => !ConvertUtils.JudgeItemTypeAboutBush(item.ItemNameType));
                        for(int i = 0; i < BushRItemList.Count; i++)
                        {
                            Boolean GPF = BushRItemList[i].ItemCode.Contains("Guide");
                            Boolean SPF = BushRItemList[i].ItemCode.Contains("Support");
                            if (GPF)
                            {
                                int gpIndex = NoBushRItemList.FindIndex(item => item.ItemCode.Contains("GuidePin"));
                                if(gpIndex != -1)
                                    BushRItemList[i].HolePitchType = NoBushRItemList[gpIndex].HolePitchType;
                            }
                            if (SPF)
                            {
                                int spIndex = NoBushRItemList.FindIndex(item => item.ItemCode.Contains("SupportPin"));
                                if (spIndex != -1)
                                    BushRItemList[i].HolePitchType = NoBushRItemList[spIndex].HolePitchType;
                            }
                        }
                        RItemList = new List<SingleItem>();
                        if (NoBushRItemList.Count > 0)
                            RItemList.AddRange(NoBushRItemList);
                        if (BushRItemList.Count > 0)
                            RItemList.AddRange(BushRItemList);
                    }

                    if (RItemList.Count > 0)
                    {
                        for (int i = 0; i < RItemList.Count; i++)
                        {
                            IHPSInfo IInfo = new IHPSInfo();
                            IInfo.ItemUID = RItemList[i].ItemUID;
                            IInfo.ItemCode = RItemList[i].ItemCode;
                            IInfo.ItemNameType = RItemList[i].ItemNameType;
                            IInfo.SType = RItemList[i].HolePitchType;
                            IInfo.RType = RHoleSceneType.R;

                            if (RItemList[i].TDBoard.BoardCode != null)
                                IInfo.GoByBoardList.Add(RItemList[i].TDBoard.BoardUID);

                            if (RItemList[i].BlindHoleBoard.BoardCode != null)
                                IInfo.GoByBoardList.Add(RItemList[i].BlindHoleBoard.BoardUID);

                            if (RItemList[i].ItemDimThroughHBList.Count > 0)
                            {
                                List<string> IDTHinfoList = RItemList[i].ItemDimThroughHBList.Select(item => item.BoardUID).ToList();
                                IInfo.GoByBoardList.AddRange(IDTHinfoList);
                            }

                            if (RItemList[i].ScrewDimThroughHBList.Count > 0)
                            {
                                List<string> SDTHinfoList = RItemList[i].ScrewDimThroughHBList.Select(item => item.BoardUID).ToList();
                                IInfo.GoByBoardList.AddRange(SDTHinfoList);
                            }

                            //For Bush
                            if (RItemList[i].BushBoardList.Count > 0)
                            {
                                List<string> BBHinfoList = RItemList[i].BushBoardList.Select(item => item.BoardUID).ToList();
                                IInfo.GoByBoardList.AddRange(BBHinfoList);
                            }

                            if (IInfo.GoByBoardList.Count > 0)
                                IInfo.GoByBoardList = IInfo.GoByBoardList.Distinct().ToList();

                            RItemPitchList.Add(IInfo);
                        }
                    }
                }
                //不在标准中
                else
                {
                    if (RItemList.Count > 0)
                    {
                        for (int i = 0; i < RItemList.Count; i++)
                        {
                            RItemList.ForEach(item => item.HolePitchType = ItemHolesPitchType.NS);
                            IHPSInfo IInfo = new IHPSInfo();
                            //if (RItemList[i].Count > 0)
                            //{
                            //    List<string> BKHinfoList = RItemList[i].BKHoleBoardList.Select(item => item.BoardUID).ToList();
                            //    IInfo.GoByBoardList.AddRange(BKHinfoList);
                            //}
                            IInfo.ItemUID = RItemList[i].ItemUID;
                            IInfo.ItemNameType = RItemList[i].ItemNameType;
                            IInfo.SType = RItemList[i].HolePitchType;
                            IInfo.RType = RHoleSceneType.R;
                            RItemPitchList.Add(IInfo);
                        }
                    }
                }

                //(this moment NRItemPitchList Comtains Two Part: In TV But No Be R && Has No In TV)
                if (NRItemPitchList.Count > 0)
                {
                    //TV Hole 
                    List<ScrewHole> tvsmallList = HoleCandidateShareData.SmallScrewCList;
                    List<ScrewHole> tvbigScrewList = HoleCandidateShareData.BigScrewCList;
                    List<ScrewHole> tvepfpScrewList = HoleCandidateShareData.FallerScrewCList;
                    List<ScrewHole> tvrpList = HoleCandidateShareData.ReturnPinCList;
                    List<ScrewHole> tvgpList = HoleCandidateShareData.GPScrewCList;
                    List<ScrewHole> tvspList = HoleCandidateShareData.SPScrewCList;

                    MixedCAD_Point cpInfo = RecognizeUtils.WholeTopViewData.ModlCenterInfo;
                    if (cpInfo.TransF)
                    {
                        CAD_Point tvcPoint = cpInfo.TransSplitPoint;

                        //tvsmallList = CU.TransToDBRefSHList(tvcPoint, tvsmallList);
                        //tvbigScrewList = CU.TransToDBRefSHList(tvcPoint, tvbigScrewList);
                        //tvepfpScrewList = CU.TransToDBRefSHList(tvcPoint, tvepfpScrewList);
                        //tvrpList = CU.TransToDBRefSHList(tvcPoint, tvrpList);
                        //tvgpList = CU.TransToDBRefSHList(tvcPoint, tvgpList);
                        //tvspList = CU.TransToDBRefSHList(tvcPoint, tvspList);
                    }


                    //N R ItemName Merge With TV Hole
                    int tpIndex = NRItemPitchList.FindIndex(item => item.ItemCode.Equals("TopPanelScrew"));
                    if (tpIndex != -1)
                    {
                        if (tvbigScrewList.Count > 0)
                        {
                            IHPSInfo ItemHoelInfo = NRItemPitchList[tpIndex];
                            ItemHoelInfo.RType = RHoleSceneType.T;
                            if (DBSHList.Count > 0)
                            {
                                List<StandardHoleData> dbTargetList = DBSHList.FindAll(item => item.Item.Equals("大螺丝"));
                                if(dbTargetList.Count > 0)
                                {
                                    Boolean SF = CU.CompareTVAndDBHole(tvbigScrewList, dbTargetList);
                                    if (SF)
                                        ItemHoelInfo.SType = ItemHolesPitchType.SS;
                                    else
                                        ItemHoelInfo.SType = ItemHolesPitchType.NS;
                                }
                            }
                        }
                    }

                    int fangtieIndex = NRItemPitchList.FindIndex(item => item.ItemCode.Equals("SpaceBlockScrew"));
                    if (fangtieIndex != -1)
                    {
                        if (tvbigScrewList.Count > 0)
                        {
                            IHPSInfo ItemHoelInfo = NRItemPitchList[fangtieIndex];
                            ItemHoelInfo.RType = RHoleSceneType.T;
                            if (DBSHList.Count > 0)
                            {
                                List<StandardHoleData> dbTargetList = DBSHList.FindAll(item => item.Item.Equals("大螺丝"));
                                if(dbTargetList != null)
                                {
                                    Boolean SF = CU.CompareTVAndDBHole(tvbigScrewList, dbTargetList);
                                    if (SF)
                                        ItemHoelInfo.SType = ItemHolesPitchType.SS;
                                    else
                                        ItemHoelInfo.SType = ItemHolesPitchType.NS;
                                }
                            }
                        }
                    }

                    int bpIndex = NRItemPitchList.FindIndex(item => item.ItemCode.Equals("BottomPanelScrew"));
                    if (bpIndex != -1)
                    {
                        if (tvsmallList.Count > 0)
                        {
                            IHPSInfo ItemHoelInfo = NRItemPitchList[bpIndex];
                            ItemHoelInfo.RType = RHoleSceneType.T;
                            if (DBSHList.Count > 0)
                            {
                                List<StandardHoleData> dbTargetList = DBSHList.FindAll(item => item.Item.Equals("小螺丝"));
                                if(dbTargetList != null)
                                {
                                    Boolean SF = CU.CompareTVAndDBHole(tvsmallList, dbTargetList);
                                    if (SF)
                                        ItemHoelInfo.SType = ItemHolesPitchType.SS;
                                    else
                                        ItemHoelInfo.SType = ItemHolesPitchType.NS;
                                }
                            }
                        }
                    }

                    int epfpIndex = NRItemPitchList.FindIndex(item => item.ItemCode.Equals("PinBoardScrew"));
                    if (epfpIndex != -1)
                    {
                        if (tvepfpScrewList.Count > 0)
                        {
                            IHPSInfo ItemHoelInfo = NRItemPitchList[epfpIndex];
                            ItemHoelInfo.RType = RHoleSceneType.T;
                            if (DBSHList.Count > 0)
                            {
                                List<StandardHoleData> dbTargetList = DBSHList.FindAll(item => item.Item.Equals("针板螺丝"));
                                if(dbTargetList.Count > 0)
                                {
                                    Boolean SF = CU.CompareTVAndDBHole(tvepfpScrewList, dbTargetList);
                                    if (SF)
                                        ItemHoelInfo.SType = ItemHolesPitchType.SS;
                                    else
                                        ItemHoelInfo.SType = ItemHolesPitchType.NS;
                                }
                            }
                        }
                    }

                    int rpIndex = NRItemPitchList.FindIndex(item => item.ItemCode.Equals("ReturnPin"));
                    if (rpIndex != -1)
                    {
                        if (tvrpList.Count > 0)
                        {
                            IHPSInfo ItemHoelInfo = NRItemPitchList[rpIndex];
                            ItemHoelInfo.RType = RHoleSceneType.T;
                            if (DBSHList.Count > 0)
                            {
                                List<StandardHoleData> dbTargetList = DBSHList.FindAll(item => item.Item.Equals("回针"));
                                if(dbTargetList != null)
                                {
                                    Boolean SF = CU.CompareTVAndDBHole(tvrpList, dbTargetList);
                                    if (SF)
                                        ItemHoelInfo.SType = ItemHolesPitchType.SS;
                                    else
                                        ItemHoelInfo.SType = ItemHolesPitchType.NS;
                                }
                            }
                        }
                    }

                    int gpIndex = NRItemPitchList.FindIndex(item => item.ItemCode.Equals("GuidePin"));
                    if (gpIndex != -1)
                    {
                        if (tvgpList.Count > 0)
                        {
                            IHPSInfo ItemHoelInfo = NRItemPitchList[gpIndex];
                            ItemHoelInfo.RType = RHoleSceneType.T;
                            if (DBSHList.Count > 0)
                            {
                                List<StandardHoleData> dbTargetList = DBSHList.FindAll(item => item.Item.Equals("导柱"));
                                if(dbTargetList != null)
                                {
                                    Boolean SF = CU.CompareTVAndDBHole(tvgpList, dbTargetList);
                                    if (SF)
                                        ItemHoelInfo.SType = ItemHolesPitchType.SS;
                                    else
                                        ItemHoelInfo.SType = ItemHolesPitchType.NS;
                                }
                            }
                        }
                    }

                    int spIndex = NRItemPitchList.FindIndex(item => item.ItemCode.Equals("SupportPin"));
                    if (spIndex != -1)
                    {
                        if (tvspList.Count > 0)
                        {
                            IHPSInfo ItemHoelInfo = NRItemPitchList[spIndex];
                            ItemHoelInfo.RType = RHoleSceneType.T;
                            if (DBSHList.Count > 0)
                            {
                                List<StandardHoleData> dbTargetList = DBSHList.FindAll(item => item.Item.Equals("拉杆"));
                                if(dbTargetList != null)
                                {
                                    Boolean SF = CU.CompareTVAndDBHole(tvspList, dbTargetList);
                                    if (SF)
                                        ItemHoelInfo.SType = ItemHolesPitchType.SS;
                                    else
                                        ItemHoelInfo.SType = ItemHolesPitchType.NS;
                                }
                            }
                        }
                    }
                }

                //Split Two Part
                if (NRItemPitchList.Count > 0)
                {
                    Boolean HasF = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("fangtie")) != -1;
                    if (!HasF)
                        NRItemPitchList = NRItemPitchList.FindAll(item => !item.ItemCode.Equals("SpaceBlockScrew")).ToList();
                    if (NRItemPitchList.Count > 0)
                    {
                        NinTVItemPitchList = NRItemPitchList.FindAll(item => item.RType != RHoleSceneType.T);
                        if (NinTVItemPitchList.Count > 0)
                            NinTVItemPitchList.ForEach(item => item.RType = RHoleSceneType.NT);
                        NRItemPitchList = NRItemPitchList.FindAll(item => item.RType == RHoleSceneType.T);
                    }
                }

                //Special Rule
                if (NinTVItemPitchList.Count > 0)
                {
                    int NinepfpScrewIndex = NinTVItemPitchList.FindIndex(item => item.ItemCode.Equals("PinBoardScrew"));
                    int NinFScrewIndex = NinTVItemPitchList.FindIndex(item => item.ItemCode.Equals("SpaceBlockScrew"));
                    int NintpScrewIndex = NinTVItemPitchList.FindIndex(item => item.ItemCode.Equals("TopPanelScrew"));
                    int NinbpScrewIndex = NinTVItemPitchList.FindIndex(item => item.ItemCode.Equals("BottomPanelScrew"));

                    Boolean NRPF = NinepfpScrewIndex != -1;
                    Boolean NinFScrewF = NinFScrewIndex != -1;
                    Boolean NinTPScrewF = NintpScrewIndex != -1;
                    Boolean NIntvBPScrewF = NinbpScrewIndex != -1;
                    List<IHPSInfo> OperRList = RItemPitchList.FindAll(item => item.ItemCode != null).ToList();
                    List<IHPSInfo> OperNRList = NRItemPitchList.FindAll(item => item.ItemCode != null).ToList();
                    //Judge epfpScrew By ReturnPin
                    int rRpSIndex = OperRList.FindIndex(item => item.ItemCode.Equals("ReturnPin") && item.SType == ItemHolesPitchType.SS);
                    int tvRpSIndex = OperNRList.FindIndex(item => item.ItemCode.Equals("ReturnPin") && item.SType == ItemHolesPitchType.SS);
                    Boolean RPF = rRpSIndex != -1 || tvRpSIndex != -1;
                    if (NRPF && RPF)
                        NinTVItemPitchList[NinepfpScrewIndex].SType = ItemHolesPitchType.NS;

                    //Judge fangtieScrew/ TopPanelScrew  By GP/SP
                    int rspSIndex = OperRList.FindIndex(item => (item.ItemCode.Equals("SupportPin") || item.ItemCode.Equals("NoNozzleMesonSupportPin"))
                    && item.SType == ItemHolesPitchType.SS);
                    int tvspSIndex = OperNRList.FindIndex(item => item.ItemCode.Equals("SupportPin") && item.SType == ItemHolesPitchType.SS);

                    int rgpSIndex = OperRList.FindIndex(item => item.ItemCode.Equals("GuidePin") && item.SType == ItemHolesPitchType.SS);
                    int tvgpSIndex = OperNRList.FindIndex(item => item.ItemCode.Equals("GuidePin") && item.SType == ItemHolesPitchType.SS);

                    Boolean SPF = rspSIndex != -1 || tvspSIndex != -1;
                    Boolean GPF = rgpSIndex != -1 || tvgpSIndex != -1;

                    if (NinFScrewF && (SPF || GPF))
                        NinTVItemPitchList[NinFScrewIndex].SType = ItemHolesPitchType.NS;
                    if (NinTPScrewF && (SPF || GPF))
                        NinTVItemPitchList[NintpScrewIndex].SType = ItemHolesPitchType.NS;

                    //Judge epScrew
                    if (NIntvBPScrewF)
                        NinTVItemPitchList[NinbpScrewIndex].SType = ItemHolesPitchType.NS;
                }

                List<BoardSectionItem> BList = AssemblyShareData.ASectionList;
                //Relevance BoardCode & BoardUID
                if (NRItemPitchList.Count > 0)
                {
                    for (int i = 0; i < NRItemPitchList.Count; i++)
                    {
                        List<string> targetUIDList = new List<string>();
                        List<string> BCodeList = NRItemPitchList[i].GoByBoardList;
                        for (int j = 0; j < BCodeList.Count; j++)
                        {
                            List<BoardSectionItem> tempBList = BList.FindAll(item => item.BoardCode.Equals(BCodeList[j]));
                            if (tempBList.Count > 0)
                            {
                                List<string> toAddUIDList = tempBList.Select(item => item.BoardUID).ToList();
                                targetUIDList.AddRange(toAddUIDList);
                            }
                        }
                        NRItemPitchList[i].GoByBoardList = targetUIDList;
                    }
                }
                if (NinTVItemPitchList.Count > 0)
                {
                    for (int i = 0; i < NinTVItemPitchList.Count; i++)
                    {
                        List<string> targetUIDList = new List<string>();
                        List<string> BCodeList = NinTVItemPitchList[i].GoByBoardList;
                        for (int j = 0; j < BCodeList.Count; j++)
                        {
                            List<BoardSectionItem> tempBList = BList.FindAll(item => item.BoardCode.Equals(BCodeList[j]));
                            if (tempBList.Count > 0)
                            {
                                List<string> toAddUIDList = tempBList.Select(item => item.BoardUID).ToList();
                                targetUIDList.AddRange(toAddUIDList);
                            }
                        }
                        NinTVItemPitchList[i].GoByBoardList = targetUIDList;
                    }
                }

                //Merge & Analyze Reckon
                List<IHPSInfo> finalIHPSInfoList = new List<IHPSInfo>();
                if (RItemPitchList.Count > 0)
                    finalIHPSInfoList.AddRange(RItemPitchList);
                if (NRItemPitchList.Count > 0)
                    finalIHPSInfoList.AddRange(NRItemPitchList);
                if (NinTVItemPitchList.Count > 0)
                    finalIHPSInfoList.AddRange(NinTVItemPitchList);

                if (finalIHPSInfoList.Count > 0)
                {
                    for (int i = 0; i < BList.Count; i++)
                    {
                        List<IHPSInfo> fitList = finalIHPSInfoList.FindAll(item => item.GoByBoardList.Contains(BList[i].BoardUID));
                        int inBoardItemNum = fitList.Count;
                        if (inBoardItemNum == 0)
                            BList[i].PitchHoleStandard = StandardType.Standard;
                        else
                        {
                            int itemSNum = fitList.FindAll(item => item.SType == ItemHolesPitchType.SS).Count();
                            if (inBoardItemNum == itemSNum && itemSNum > 0)
                                BList[i].PitchHoleStandard = StandardType.Standard;
                            else
                                BList[i].PitchHoleStandard = StandardType.NonStandard;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }

        }

        public static RefHoleCenterSplitInfo TranRefCHoleData(DItemNameType NameType, List<ScrewHole> CItemList)
        {
            RefHoleCenterSplitInfo Info = new RefHoleCenterSplitInfo();
            Info.ItemNameType = NameType;
            Info.DBItemName = CU.TranDBStrandHoleItemName(NameType);
            Info.SplitInfoList = new List<StandardHoleData>();
            MixedCAD_Point modlHInfo = RecognizeUtils.WholeTopViewData.ModlCenterInfo;
            double CX = modlHInfo.CustomerPoint.X;
            double CY = modlHInfo.CustomerPoint.Y;
            if (CItemList.Count > 0)
            {
                List<HoleAbsDistance> DisList = new List<HoleAbsDistance>();
                Info.DBDim = Convert.ToInt32(Math.Round(CItemList[0].Dim, 0));
                for (int i = 0; i < CItemList.Count; i++)
                {
                    StandardHoleData TItem = new StandardHoleData();
                    double ItemX = Convert.ToDouble(Math.Round(CItemList[i].CenterPoint.CustomerPoint.X - CX, 1));
                    double ItemY = Convert.ToDouble(Math.Round(CItemList[i].CenterPoint.CustomerPoint.Y - CY, 1));
                    TItem.ItemDim = Info.DBDim;
                    TItem.ItemX = ItemX;
                    TItem.ItemY = ItemY;
                    TItem.fPosType = CItemList[i].fPosType;
                    Info.SplitInfoList.Add(TItem);
                    double absX = Math.Abs(ItemX);
                    double absY = Math.Abs(ItemY);
                    HoleAbsDistance DisItem = new HoleAbsDistance();
                    DisItem.absX = absX;
                    DisItem.absY = absY;
                    DisList.Add(DisItem);
                }

                var MF = DisList.GroupBy(o => new { o.absX, o.absY }).OrderByDescending(g => g.Count()).First();
                int maxCount = MF.Count();
                List<HoleAbsDistance> partialMF = DisList
                    .GroupBy(o => new { o.absX, o.absY })
                    .Where(g => g.Count() != maxCount)
                    .SelectMany(g => g)
                    .ToList();
                if(partialMF.Count > 0)
                {
                    List<StandardHoleData> sList = Info.SplitInfoList;
                    for(int i = 0; i < sList.Count; i++)
                    {
                        Boolean F = partialMF.FindIndex(item => item.absX == Math.Abs(sList[i].ItemX) &&
                        item.absY != Math.Abs(sList[i].ItemY)) == -1;
                        if (F)
                            sList[i].partialF = true;
                    }
                }
            }
            return Info;
        }

        public static Boolean JudgeSHDataMatchCItemHole(StandardHoleData SItem, string ConName, ScrewHole CItem)
        {
            MixedCAD_Point modlHInfo = RecognizeUtils.WholeTopViewData.ModlCenterInfo;
            double CX = modlHInfo.CustomerPoint.X;
            double CY = modlHInfo.CustomerPoint.Y;
            Boolean F1 = SItem.Item.Equals(ConName);
            Boolean F2 = SItem.ItemDim == CItem.Dim;
            int ItemX = Convert.ToInt32(Math.Round(CItem.CenterPoint.CustomerPoint.X - CX, 0));
            int ItemY = Convert.ToInt32(Math.Round(CItem.CenterPoint.CustomerPoint.Y - CY, 0));
            Boolean F3 = SItem.ItemX == ItemX;
            Boolean F4 = SItem.ItemY == ItemY;
            return F1 && F2 && F3 && F4;
        }

        //Process Top View Rec Frame Info
        public static void ProcessTopViewFrameData(CJudgeType BJ)
        {
            FrameInfoData.FRItem = new FrameItem();
            List<FrameLineInfo> FCList = FrameInfoData.FCList;
            if (FCList.Count != 0)
            {
                double? MinY = null;
                double? MaxY = null;
                double? MinX = null;
                double? MaxX = null;
                Boolean TNumF = false;
                Boolean VNumF = false;

                List<FrameLineInfo> TList = FCList.FindAll(item => item.FLineType == FrameLineType.T);
                List<FrameLineInfo> VList = FCList.FindAll(item => item.FLineType == FrameLineType.V);
                List<FrameLineInfo> arcList = FCList.FindAll(item => item.FLineType == FrameLineType.ARC);
                if (TList.Count > 1)
                {
                    MinY = TList.Min(item => item.TVLine.StartPoint.CustomerPoint.Y);
                    MaxY = TList.Max(item => item.TVLine.StartPoint.CustomerPoint.Y);
                    VNumF = true;
                }
                if (VList.Count > 1)
                {
                    MinX = VList.Min(item => item.TVLine.StartPoint.CustomerPoint.X);
                    MaxX = VList.Max(item => item.TVLine.StartPoint.CustomerPoint.X);
                    TNumF = true;
                }
                //Compatible
                if (TList.Count > 0 && !VNumF)
                {
                    MinX = TList[0].TVLine.StartPoint.CustomerPoint.X;
                    MaxX = TList[0].TVLine.EndPoint.CustomerPoint.X;
                }
                if (VList.Count > 0 && !TNumF)
                {
                    MaxY = VList[0].TVLine.StartPoint.CustomerPoint.Y;
                    MinY = VList[0].TVLine.EndPoint.CustomerPoint.Y;
                }
                if (MinX != null && MaxX != null && MinY != null && MaxY != null)
                {
                    //4 Point
                    CAD_Point TLP = new CAD_Point((double)MinX, (double)MaxY, 0);
                    CAD_Point BLP = new CAD_Point((double)MinX, (double)MinY, 0);
                    CAD_Point TRP = new CAD_Point((double)MaxX, (double)MaxY, 0);
                    CAD_Point BRP = new CAD_Point((double)MaxX, (double)MinY, 0);
                    //L
                    double FrameLength = Math.Round((double)MaxY - (double)MinY, 2);
                    double FrameWidth = Math.Round((double)MaxX - (double)MinX, 2);
                    FrameInfoData.FRItem.FrameLength = FrameLength;
                    FrameInfoData.FRItem.FrameWidth = FrameWidth;
                    //↑↓
                    CAD_Line TT = new CAD_Line();
                    TT.StartPoint.X = (double)MinX;
                    TT.StartPoint.Y = (double)MaxY;
                    TT.EndPoint.X = (double)MaxX;
                    TT.EndPoint.Y = (double)MaxY;
                    CAD_Line TB = new CAD_Line();
                    TB.StartPoint.X = (double)MinX;
                    TB.StartPoint.Y = (double)MinY;
                    TB.EndPoint.X = (double)MinX;
                    TB.EndPoint.Y = (double)MinY;
                    //← →
                    CAD_Line VL = new CAD_Line();
                    VL.StartPoint.X = (double)MinX;
                    VL.StartPoint.Y = (double)MaxY;
                    VL.EndPoint.X = (double)MinX;
                    VL.EndPoint.Y = (double)MinY;
                    CAD_Line VR = new CAD_Line();
                    VR.StartPoint.X = (double)MaxX;
                    VR.StartPoint.Y = (double)MaxY;
                    VR.EndPoint.X = (double)MaxX;
                    VR.EndPoint.Y = (double)MinY;

                    if (BJ == CJudgeType.Y)
                    {
                        double DTY = Math.Abs(Math.Round(TT.StartPoint.Y, 2));
                        double DBY = Math.Abs(Math.Round(TB.StartPoint.Y, 2));
                        double DLX = Math.Abs(Math.Round(VL.StartPoint.X, 2));
                        double DRX = Math.Abs(Math.Round(VR.StartPoint.X, 2));
                        Boolean F1 = DTY == DBY;
                        Boolean F2 = DLX == DRX;
                        FrameInfoData.FRItem.CSPoint.X = Math.Abs(DLX - DRX);
                        FrameInfoData.FRItem.CSPoint.Y = Math.Abs(DTY - DBY);
                        if (F1 && F2)
                            FrameInfoData.FRItem.FSType = FrameSplitType.S;
                        else
                            FrameInfoData.FRItem.FSType = FrameSplitType.N;
                    }

                    if (BJ == CJudgeType.N)
                    {
                        //Calculate Coor To Judge Center Spliting Scene
                        MixedCAD_Point modlHInfo = RecognizeUtils.WholeTopViewData.ModlCenterInfo;
                        CAD_Point TVCP = modlHInfo.CustomerPoint;
                        double DTY = Math.Abs(Math.Round(TT.StartPoint.Y - TVCP.Y, 2));
                        double DBY = Math.Abs(Math.Round(TVCP.Y - TB.StartPoint.Y, 2));
                        double DLX = Math.Abs(Math.Round(TVCP.X - VL.StartPoint.X, 2));
                        double DRX = Math.Abs(Math.Round(VR.StartPoint.X - TVCP.X, 2));
                        Boolean F1 = DTY == DBY;
                        Boolean F2 = DLX == DRX;
                        FrameInfoData.FRItem.CSPoint.X = Math.Abs(DLX - DRX);
                        FrameInfoData.FRItem.CSPoint.Y = Math.Abs(DTY - DBY);
                        if (F1 && F2)
                            FrameInfoData.FRItem.FSType = FrameSplitType.S;
                        else
                            FrameInfoData.FRItem.FSType = FrameSplitType.N;
                    }

                    if (arcList.Count > 0)
                    {
                        for (int i = 0; i < arcList.Count; i++)
                        {
                            // >= 180 5 Error
                            Boolean AF = arcList[i].ArcLine.Angle >= 175;
                            double Raduis = arcList[i].ArcLine.Radius;
                            AngleType AT = AngleType.NONE;
                            AngleDir AD = AngleDir.NONE;
                            if (AF)
                            {
                                //X/Y BK
                                AngleType T1 = CU.JudgeFArcXYBKOrNo(arcList[i].ArcLine, TT, FrameLineType.T);
                                AngleType T2 = CU.JudgeFArcXYBKOrNo(arcList[i].ArcLine, TB, FrameLineType.T);
                                AngleType T3 = CU.JudgeFArcXYBKOrNo(arcList[i].ArcLine, VL, FrameLineType.V);
                                AngleType T4 = CU.JudgeFArcXYBKOrNo(arcList[i].ArcLine, VR, FrameLineType.V);
                                List<AngleType> ATList = new List<AngleType>() { T1, T2, T3, T4 };
                                int BKTypeIndex = ATList.FindIndex(item => item != AngleType.NONE);
                                if (BKTypeIndex != -1)
                                    AT = ATList[BKTypeIndex];
                                else
                                    AT = AngleType.BK;
                            }
                            else
                                AT = AngleType.COR;
                            AD = CU.JudgeFrameAngleDir(arcList[i].ArcLine, TLP, BLP, TRP, BRP);
                            CU.SetFrameItemData(FrameInfoData.FRItem, AD, AT, Raduis);
                        }
                    }

                    //no standard Paint
                    List<MixedCAD_Arc> tempArcList = new List<MixedCAD_Arc>(WholeTopViewData.ArcList);
                    if (tempArcList.Count > 0)
                    {
                        List<MixedCAD_Arc> maybeFrameArcList = new List<MixedCAD_Arc>();
                        //BK
                        if (FrameInfoData.FRItem.BL_Type == AngleType.NONE)
                        {
                            int LBBK = tempArcList.FindIndex(item => CU.JudgeNoStandArcBK(item, VL.EndPoint.X, TB.StartPoint.Y));
                            if (LBBK != -1)
                            {
                                FrameInfoData.FRItem.BL_Type = AngleType.BK;
                                FrameInfoData.FRItem.BL_Radius = Math.Round(tempArcList[LBBK].Radius, 0);
                            }
                        }

                        if (FrameInfoData.FRItem.BR_Type == AngleType.NONE)
                        {
                            int RBBK = tempArcList.FindIndex(item => CU.JudgeNoStandArcBK(item, VR.EndPoint.X, TB.StartPoint.Y));
                            if (RBBK != -1)
                            {
                                FrameInfoData.FRItem.BR_Type = AngleType.BK;
                                FrameInfoData.FRItem.BR_Radius = Math.Round(tempArcList[RBBK].Radius, 0);
                            }
                        }

                        if (FrameInfoData.FRItem.TL_Type == AngleType.NONE)
                        {
                            int LTBK = tempArcList.FindIndex(item => CU.JudgeNoStandArcBK(item, VL.EndPoint.X, TT.StartPoint.Y));
                            if (LTBK != -1)
                            {
                                FrameInfoData.FRItem.TL_Type = AngleType.BK;
                                FrameInfoData.FRItem.TL_Radius = Math.Round(tempArcList[LTBK].Radius, 0);
                            }
                        }

                        if (FrameInfoData.FRItem.TR_Type == AngleType.NONE)
                        {
                            int RTBK = tempArcList.FindIndex(item => CU.JudgeNoStandArcBK(item, VR.EndPoint.X, TT.StartPoint.Y));
                            if (RTBK != -1)
                            {
                                FrameInfoData.FRItem.TR_Type = AngleType.BK;
                                FrameInfoData.FRItem.TR_Radius = Math.Round(tempArcList[RTBK].Radius, 0);
                            }
                        }

                    }

                }
                
            }
            else
            {
                MessageBox.Show(UserPromptErrorType.CanNotSelectFrameLine);
                return;
            }
        }

        //处理某块板的精框数据
        public static void ProcessBoardAssemblyFrameData(MixedCAD_Line line, int boardRowIndex)
        {
            //关联框和板
            double FSY = Math.Round(line.StartPoint.CustomerPoint.Y, 3);
            double FEY = Math.Round(line.EndPoint.CustomerPoint.Y, 3);
            double FMaxY = FSY > FEY ? FSY : FEY;
            double FMinY = FSY < FEY ? FSY : FEY;
            BoardSectionItem targetBoard = AssemblyShareData.AUIBlueSectionList[boardRowIndex];
            double boardMaxY = targetBoard.OverheadLine.StartPoint.CustomerPoint.Y;
            double boardMinY = targetBoard.BottomLine.StartPoint.CustomerPoint.Y;
            //0全部包含 1 上部 2 下部  3整条直线穿过这件板 这个不在考虑内 -1 未判定(不在考虑内)
            int judgeIndex = -1;
            double Depth = -1;
            Boolean F1 = boardMinY <= FMaxY && FMaxY <= boardMaxY;
            Boolean F2 = boardMinY <= FMinY && FMinY <= boardMaxY;
            if (F1 && !F2)
                judgeIndex = 1;
            if (!F1 && F2)
                judgeIndex = 2;
            if (F1 && F2)
                judgeIndex = 0;
            //设置板 精框数据
            if (judgeIndex != -1)
            {
                if (judgeIndex == 0)
                    Depth = FMaxY - FMinY;
                if (judgeIndex == 1)
                    Depth = FMaxY - boardMinY;
                if (judgeIndex == 2)
                    Depth = boardMaxY - FMinY;
                if (Depth != -1)
                    FrameInfoData.FRItem.FrameDepth = Math.Round(Depth, 2);
                FrameSpeRule();
                targetBoard.frameItem = (FrameItem)ConvertUtils.DeepCopyObject(FrameInfoData.FRItem);
                SetFrameItemTig(boardRowIndex);
            }
            else
                MessageBox.Show("框线不在该板区域中 请检查!");
            AutoTypeCRUIAfterRecognizeEvent(RenderType.AfterRecoginzeFrame);
        }



        public static void ATypeSetFrameItemTigInfo(int Index)
        {
            FrameSplitType FST = FrameInfoData.FRItem.FSType;
            List<BoardSectionItem> SList = AssemblyShareData.AUIBlueSectionList;
            string SameATS = null;
            string SameASS = null;
            SList[Index].frameItem.Tig = "";
            SList[Index].frameItem.BoardUID = SList[Index].BoardUID;
            SList[Index].frameItem.BoardName = SList[Index].BoardName;
            double L = SList[Index].frameItem.FrameLength;
            double W = SList[Index].frameItem.FrameWidth;
            double D = SList[Index].frameItem.FrameDepth;
            string SizeStr = L.ToString() + "*" + W.ToString() + "*" + D.ToString();

            double TL = SList[Index].frameItem.TL_Radius;
            double TR = SList[Index].frameItem.TR_Radius;
            double BL = SList[Index].frameItem.BL_Radius;
            double BR = SList[Index].frameItem.BR_Radius;

            AngleType BLType = SList[Index].frameItem.BL_Type;
            AngleType BRType = SList[Index].frameItem.BR_Type;
            AngleType TLType = SList[Index].frameItem.TL_Type;
            AngleType TRType = SList[Index].frameItem.TR_Type;

            string frameTypeStr = FrameInfoData.FRItem.FrameType;
            //Standard Info
            AngleInfo BaseAngleInfo = WholeTopViewData.BaseAngleInfo;
            //Now Default Base 
            BaseAngleInfo.AType = BRType;
            BaseAngleInfo.Radius = BR;
            if (FST == FrameSplitType.S)
                SList[Index].frameItem.Tig += "分中";
            if (frameTypeStr.Equals(" "))
                SList[Index].frameItem.FrameType = "J";
            if (frameTypeStr.Equals("J"))
                SList[Index].frameItem.Tig += "精";
            if (frameTypeStr.Equals("C"))
                SList[Index].frameItem.Tig += "粗";
            SList[Index].frameItem.Tig += "框";
            SList[Index].frameItem.Tig += SizeStr;

            Boolean SameTypeF = BLType == BRType && BLType == TLType && BLType == TRType;
            Boolean SameRF = BL == TR && BL == TL && BL == BR;

            if (SameTypeF)
            {
                if (BLType == AngleType.XBK)
                    SameATS = " X避空";
                if (BLType == AngleType.YBK)
                    SameATS = " Y避空";
                if (BLType == AngleType.BK)
                    SameATS = " 避空角";
                if (BLType == AngleType.COR)
                    SameATS = " 转角";
            }
            if (SameRF)
                SameASS = BL.ToString();

            if (SameTypeF && SameRF)
                SList[Index].frameItem.Tig += SameATS + "R" + SameASS;
            else
            {
                AngleInfo BRInfo = new AngleInfo();
                BRInfo.DirType = AngleDir.BR;
                BRInfo.Radius = BR;
                BRInfo.AType = BRType;

                AngleInfo BLInfo = new AngleInfo();
                BLInfo.DirType = AngleDir.BL;
                BLInfo.Radius = BL;
                BLInfo.AType = BLType;

                AngleInfo TLInfo = new AngleInfo();
                TLInfo.DirType = AngleDir.TL;
                TLInfo.Radius = TL;
                TLInfo.AType = TLType;

                AngleInfo TRInfo = new AngleInfo();
                TRInfo.DirType = AngleDir.TR;
                TRInfo.Radius = TR;
                TRInfo.AType = TRType;

                //非基准信息
                List<AngleInfo> OAInfoList = new List<AngleInfo>();
                if (BaseAngleInfo.DirType == AngleDir.BR)
                {
                    OAInfoList.Add(BLInfo);
                    OAInfoList.Add(TLInfo);
                    OAInfoList.Add(TRInfo);
                }
                if (BaseAngleInfo.DirType == AngleDir.BL)
                {
                    OAInfoList.Add(BRInfo);
                    OAInfoList.Add(TLInfo);
                    OAInfoList.Add(TRInfo);
                }
                if (BaseAngleInfo.DirType == AngleDir.TL)
                {
                    OAInfoList.Add(BLInfo);
                    OAInfoList.Add(BRInfo);
                    OAInfoList.Add(TRInfo);
                }
                if (BaseAngleInfo.DirType == AngleDir.TR)
                {
                    OAInfoList.Add(BLInfo);
                    OAInfoList.Add(BRInfo);
                    OAInfoList.Add(TLInfo);
                }

                if (SameTypeF && !SameRF)
                {
                    List<double> ORList = OAInfoList.Select(item => item.Radius).ToList();
                    if (ORList.Count > 0)
                    {
                        int ORCount = ORList.ToList().Distinct().Count();
                        if (ORCount == 1)
                        {
                            double OR = ORList[0];
                            SList[Index].frameItem.Tig += SameATS + "基准R" + BaseAngleInfo.Radius + "其它R" + OR;
                        }
                    }
                }

                if (!SameTypeF && SameRF)
                {
                    List<AngleType> OATList = OAInfoList.Select(item => item.AType).ToList();
                    if (OATList.Count > 0)
                    {
                        int OTCount = OATList.Distinct().Count();
                        if (OTCount == 1)
                        {
                            AngleType OT = OATList[0];
                            if (BaseAngleInfo.AType == AngleType.BK)
                                SList[Index].frameItem.Tig += " 基准避空角R" + BaseAngleInfo.Radius;

                            if (BaseAngleInfo.AType == AngleType.COR)
                                SList[Index].frameItem.Tig += " 基准转角R" + BaseAngleInfo.Radius;

                            if (OT == AngleType.BK)
                                SList[Index].frameItem.Tig += " 其它避空角R" + SameASS;

                            if (OT == AngleType.COR)
                                SList[Index].frameItem.Tig += " 其它转角R" + SameASS;
                        }
                    }
                }

                if (!SameTypeF && !SameRF)
                {
                    List<double> ORList = OAInfoList.Select(item => item.Radius).ToList();
                    List<AngleType> OATList = OAInfoList.Select(item => item.AType).ToList();
                    if (ORList.Count > 0 && OATList.Count > 0)
                    {
                        if (ORList.Count == OATList.Count && ORList.Count == 1)
                        {
                            AngleType OT = OATList[0];
                            double OR = ORList[0];

                            if (BaseAngleInfo.AType == AngleType.BK)
                                SList[Index].frameItem.Tig += " 基准避空角R" + BaseAngleInfo.Radius;
                            if (BaseAngleInfo.AType == AngleType.COR)
                                SList[Index].frameItem.Tig += " 基准转角R" + BaseAngleInfo.Radius;

                            if (OT == AngleType.BK)
                                SList[Index].frameItem.Tig += " 其它避空角R" + OR;
                            if (OT == AngleType.COR)
                                SList[Index].frameItem.Tig += " 其它转角R" + OR;
                        }
                    }
                }
            }

            FrameInfoData.FRItem = SList[Index].frameItem;
        }
        
        public static void MTypeSetFrameItemTig(int Index)
        {
            FrameSplitType FST = FrameInfoData.FRItem.FSType;
            List<ManualBoardItem> SList = AssemblyShareData.MSectionList;
            string SameATS = null;
            string SameASS = null;
            SList[Index].frameItem.Tig = "";
            SList[Index].frameItem.BoardUID = SList[Index].BoardUID;
            SList[Index].frameItem.BoardName = SList[Index].BoardName;
            double L = SList[Index].frameItem.FrameLength;
            double W = SList[Index].frameItem.FrameWidth;
            double D = SList[Index].frameItem.FrameDepth;
            string SizeStr = L.ToString() + "*" + W.ToString() + "*" + D.ToString();

            //半径长度
            double TL = SList[Index].frameItem.TL_Radius;
            double TR = SList[Index].frameItem.TR_Radius;
            double BL = SList[Index].frameItem.BL_Radius;
            double BR = SList[Index].frameItem.BR_Radius;

            //角类型 
            AngleType SBL = SList[Index].frameItem.BL_Type;
            AngleType SBR = SList[Index].frameItem.BR_Type;
            AngleType STL = SList[Index].frameItem.TL_Type;
            AngleType STR = SList[Index].frameItem.TR_Type;

            if (FST == FrameSplitType.S)
                SList[Index].frameItem.Tig += "分中精框 ";

            SList[Index].frameItem.Tig += SizeStr;
            Boolean SameAT = SBL == SBR && SBL == STL && SBL == STR;
            Boolean SameAR = BL == TR && BL == TL && BL == BR;

            if (SameAT)
            {
                if (SBL == AngleType.BK)
                    SameATS = " 避空角";
                if (SBL == AngleType.COR)
                    SameATS = " 转角";
            }
            if (SameAR)
                SameASS = BL.ToString();

            if (SameAT && SameAR)
                SList[Index].frameItem.Tig += SameATS + "R" + SameASS;
            else
            {
                AngleInfo BRInfo = new AngleInfo();
                BRInfo.DirType = AngleDir.BR;
                BRInfo.Radius = BR;
                BRInfo.AType = SBR;

                AngleInfo BLInfo = new AngleInfo();
                BLInfo.DirType = AngleDir.BL;
                BLInfo.Radius = BL;
                BLInfo.AType = SBL;

                AngleInfo TLInfo = new AngleInfo();
                TLInfo.DirType = AngleDir.TL;
                TLInfo.Radius = TL;
                TLInfo.AType = STL;

                AngleInfo TRInfo = new AngleInfo();
                TRInfo.DirType = AngleDir.TR;
                TRInfo.Radius = TR;
                TRInfo.AType = STR;

                //基准信息
                AngleInfo BaseAngleInfo = WholeTopViewData.BaseAngleInfo;
                //非基准信息
                List<AngleInfo> OAInfoList = new List<AngleInfo>();

                if (BaseAngleInfo.DirType == AngleDir.BR)
                {
                    OAInfoList.Add(BLInfo);
                    OAInfoList.Add(TLInfo);
                    OAInfoList.Add(TRInfo);
                }
                if (BaseAngleInfo.DirType == AngleDir.BL)
                {
                    OAInfoList.Add(BRInfo);
                    OAInfoList.Add(TLInfo);
                    OAInfoList.Add(TRInfo);
                }
                if (BaseAngleInfo.DirType == AngleDir.TL)
                {
                    OAInfoList.Add(BLInfo);
                    OAInfoList.Add(BRInfo);
                    OAInfoList.Add(TRInfo);
                }
                if (BaseAngleInfo.DirType == AngleDir.TR)
                {
                    OAInfoList.Add(BLInfo);
                    OAInfoList.Add(BRInfo);
                    OAInfoList.Add(TLInfo);
                }
                //基准角与其它角 角类型一致 半径不一致
                if (SameAT && !SameAR)
                {
                    List<double> ORList = OAInfoList.Select(item => item.Radius).ToList();
                    if (ORList.Count > 0)
                    {
                        int ORCount = ORList.ToList().Distinct().Count();
                        if (ORCount == 1)
                        {
                            double OR = ORList[0];
                            SList[Index].frameItem.Tig += SameATS + "基准R" + BaseAngleInfo.Radius + "其它R" + OR;
                        }
                    }
                }
                //基准角与其它角 角类型不一致 半径一致
                if (!SameAT && SameAR)
                {
                    List<AngleType> OATList = OAInfoList.Select(item => item.AType).ToList();
                    if (OATList.Count > 0)
                    {
                        int OTCount = OATList.Distinct().Count();
                        if (OTCount == 1)
                        {
                            AngleType OT = OATList[0];
                            if (BaseAngleInfo.AType == AngleType.BK)
                                SList[Index].frameItem.Tig += " 基准转角R" + BaseAngleInfo.Radius;

                            if (BaseAngleInfo.AType == AngleType.COR)
                                SList[Index].frameItem.Tig += " 基准避空角R" + BaseAngleInfo.Radius;

                            if (OT == AngleType.BK)
                                SList[Index].frameItem.Tig += " 其它避空角R" + SameASS;

                            if (OT == AngleType.COR)
                                SList[Index].frameItem.Tig += " 其它转角R" + SameASS;
                        }
                    }
                }
                //基准角与其它角 角类型不一致 半径不一致
                if (!SameAT && !SameAR)
                {
                    List<double> ORList = OAInfoList.Select(item => item.Radius).ToList();
                    List<AngleType> OATList = OAInfoList.Select(item => item.AType).ToList();
                    if (ORList.Count > 0 && OATList.Count > 0)
                    {
                        if (ORList.Count == OATList.Count && ORList.Count == 1)
                        {
                            AngleType OT = OATList[0];
                            double OR = ORList[0];

                            if (BaseAngleInfo.AType == AngleType.BK)
                                SList[Index].frameItem.Tig += " 基准避空角R" + BaseAngleInfo.Radius;
                            if (BaseAngleInfo.AType == AngleType.COR)
                                SList[Index].frameItem.Tig += " 基准转角R" + BaseAngleInfo.Radius;

                            if (OT == AngleType.BK)
                                SList[Index].frameItem.Tig += " 其它避空角R" + OR;
                            if (OT == AngleType.COR)
                                SList[Index].frameItem.Tig += " 其它转角R" + OR;
                        }
                    }
                }
            }
        }

        /* Set Frame Tig Scene:
         * 1.  4个都一样 避空/R角 半径一样
         * 2.  4个不一样 基准R10 其它R15
         * 3.  4个不一样 基准避空角R10 其它R10 
         * 4.  基准R10 其它避空角R10
         */
        public static void SetFrameItemTig(int Index)
        {
            if (AssemblyShareData.operType == CustomOperPatternType.AUTO)
                ATypeSetFrameItemTigInfo(Index);
            if (AssemblyShareData.operType == CustomOperPatternType.MANUAL)
                MTypeSetFrameItemTig(Index);
        }

        //TP Screw F
        public static void RecognizeTopPanelScrew(Dictionary<double, List<MixedCAD_Line>> AVLineYDic, Dictionary<double, List<MixedCAD_Line>> OBLineYDic)
        {
            try
            {
                List<CSingleItem> CTempPList = new List<CSingleItem>();
                List<CSinglePartItem> PItemVList = new List<CSinglePartItem>();
                int tpBoardIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("tpBoard"));
                if (tpBoardIndex != -1)
                {
                    //Form First Board -> ABoard
                    int AutoaBoardIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("aBoard"));
                    List<BoardSectionItem> tempSectionList = AssemblyShareData.ASectionList.GetRange(0, AutoaBoardIndex + 1);
                    List<MixedCAD_Line> PVLines = new List<MixedCAD_Line>();
                    
                    List<MixedCAD_Line> PToochOBLine = new List<MixedCAD_Line>();
                    double MaxY = Math.Round(tempSectionList.Max(item => item.OverheadLine.UseStartPoint.Y), 0);
                    double MinY = Math.Round(Math.Round(tempSectionList.Min(item => item.BottomLine.UseStartPoint.Y), 0), 2);
                    List<double> PanelVLineKeys = AVLineYDic.Keys.ToList().FindAll(item => MinY <= Math.Round(item, 0) && Math.Round(item, 0) <= MaxY);
                    List<double> PanelOBLineKeys = OBLineYDic.Keys.ToList().FindAll(item => MinY <= Math.Round(item, 0) && Math.Round(item, 0) <= MaxY);
                    //Non-Standard TopPanel Screw may be outSide Fangtie 
                    if (PanelVLineKeys != null)
                        PanelVLineKeys.ForEach(key => PVLines.AddRange(AVLineYDic[key]));
                    if (PanelOBLineKeys != null)
                        PanelOBLineKeys.ForEach(key => PToochOBLine.AddRange(OBLineYDic[key]));

                    if (PVLines.Count > 0)
                    {
                        List<ScrewHole> CRList = HoleCandidateShareData.BigScrewCList;
                        ComputedUtils.SwitchTVHoleCoorType(CRList);
                        for (int i = 0; i < PVLines.Count - 1; i++)
                        {
                            for (int j = 1; j < PVLines.Count; j++)
                            {
                                if (j > i)
                                {
                                    for (int k = 0; k < CRList.Count; k++)
                                    {
                                        double TempDim = Math.Round(Math.Abs(PVLines[i].StartPoint.UsePoint.X - PVLines[j].StartPoint.UsePoint.X), 2);
                                        double TwoLineSplitAgvCX = Math.Round((PVLines[i].StartPoint.UsePoint.X + PVLines[j].StartPoint.UsePoint.X) / 2, 1);
                                        double TargetCenterX = Math.Round(CRList[k].UseCenterPoint.X, 1);
                                        double LX = TargetCenterX - 5;
                                        double RX = TargetCenterX + 5;
                                        if (LX <= TwoLineSplitAgvCX && TwoLineSplitAgvCX <= RX)
                                        {
                                            CSinglePartItem PItem = new CSinglePartItem();
                                            if (CRList[k].Dim - 0.02 <= TempDim && TempDim <= CRList[k].Dim + 0.02)
                                            {
                                                PItem.ItemType = ItemPartCodeType.Dim;
                                                PItem.LLine = PVLines[i];
                                                PItem.RLine = PVLines[j];
                                                PItem.XLength = TempDim;
                                                PItem.YLength = Math.Round(Math.Abs(PVLines[i].StartPoint.CustomerPoint.Y - PVLines[i].EndPoint.CustomerPoint.Y), 0);
                                                PItem.TVCPX = TargetCenterX;
                                                PItem.MatchScrewHole = CRList[k];
                                                PItemVList.Add(PItem);
                                            }
                                            if (CRList[k].TD - 1 <= TempDim && TempDim <= CRList[k].TD + 1)
                                            {
                                                PItem.ItemType = ItemPartCodeType.TD;
                                                PItem.LLine = PVLines[i];
                                                PItem.RLine = PVLines[j];
                                                PItem.XLength = TempDim;
                                                PItem.YLength = Math.Round(Math.Abs(PVLines[i].StartPoint.CustomerPoint.Y - PVLines[i].EndPoint.CustomerPoint.Y), 0);
                                                PItem.TVCPX = TargetCenterX;
                                                PItem.MatchScrewHole = CRList[k];
                                                PItemVList.Add(PItem);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        //Dup
                        if (PItemVList.Count > 0)
                        {
                            List<CSinglePartItem> resList = new List<CSinglePartItem>();
                            resList.Add(PItemVList[0]);
                            if (PItemVList.Count > 1)
                            {
                                for (int i = 1; i < PItemVList.Count; i++)
                                {
                                    Boolean NoSameFlag = resList.FindIndex(item => CU.JudgeEqualItemPart(item, PItemVList[i])) == -1;
                                    if (NoSameFlag)
                                        resList.Add(PItemVList[i]);
                                }
                            }
                            PItemVList = resList;
                        }
                        //Merge
                        if (PItemVList.Count > 0)
                        {
                            var GroupByList = PItemVList.GroupBy(item => item.TVCPX);
                            foreach (var Item in GroupByList)
                            {
                                List<CSinglePartItem> ItemPartList = Item.ToList();
                                CSingleItem CItem = new CSingleItem();
                                CItem.CenterPoint.CustomerPoint.X = Item.Key;
                                for (int i = 0; i < ItemPartList.Count; i++)
                                {
                                    CItem.MatchScrewHole = ItemPartList[i].MatchScrewHole;
                                    CItem.InfoList.Add(ItemPartList[i]);
                                }
                                CTempPList.Add(CItem);
                            }
                        }
                        //Begin R
                        if (CTempPList.Count > 0)
                        {
                            for (int i = 0; i < CTempPList.Count; i++)
                                CTempPList[i].RelScrewHoleList = CRList.FindAll(item =>
                                    (CTempPList[i].MatchScrewHole.Dim - 0.01 <= item.Dim && item.Dim <= CTempPList[i].MatchScrewHole.Dim + 0.01)
                                    &&
                                    (CTempPList[i].MatchScrewHole.TD - 0.01 <= item.TD && item.TD <= CTempPList[i].MatchScrewHole.TD + 0.01));
                            //Filter
                            CTempPList = CTempPList.FindAll(item => item.InfoList.Select(info => info.ItemType).Distinct().ToList().Count > 1);
                            if (CTempPList.Count > 0)
                            {
                                for (int k = 0; k < CTempPList.Count; k++)
                                {
                                    Boolean DimF = CTempPList[k].InfoList.FindIndex(item => item.ItemType == ItemPartCodeType.Dim) != -1;
                                    Boolean TDF = CTempPList[k].InfoList.FindIndex(item => item.ItemType == ItemPartCodeType.TD) != -1;
                                    if (DimF && TDF)
                                    {
                                        //大约直径
                                        double PDim = CTempPList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.Dim).Select(item => item.XLength).Distinct().Min();
                                        double DimCenterX = CTempPList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.Dim).Select(item => item.TVCPX).Distinct().First();
                                        List<SingleItem> wantAddTpScrewList = new List<SingleItem>();
                                        //识别面板螺丝 尖(牙有一定概率出现2组 只能后续去重去解决多识别问题)
                                        for (int i = 0; i < PToochOBLine.Count - 1; i++)
                                        {
                                            for (int j = 1; j < PToochOBLine.Count; j++)
                                            {
                                                if (j > i)
                                                {
                                                    double? ToothX = JudgeTwoObliqueTooth(PToochOBLine[i], PToochOBLine[j]);
                                                    Boolean InCenterLineFlag = false;
                                                    if (ToothX != null)
                                                    {
                                                        Boolean F1 = (double)ToothX - 1 <= DimCenterX;
                                                        Boolean F2 = DimCenterX <= (double)ToothX + 1;
                                                        InCenterLineFlag = F1 && F2;
                                                    }
                                                    if (InCenterLineFlag && ToothX != -1)
                                                    {
                                                        //客户来图牙深
                                                        double ToochY = 0;
                                                        //穿过的板厚
                                                        double ThroughPlateH = 0;
                                                        //客户来图能找到 尖
                                                        CTempPList[k].ToochInfo.ExistTheTip = true;
                                                        double SY = PToochOBLine[i].StartPoint.UsePoint.Y;
                                                        double EY = PToochOBLine[i].EndPoint.UsePoint.Y;
                                                        double ToochRealH = Math.Round(SY - EY,1);
                                                        //完整牙Y坐标
                                                        double ToochCompY = SY < EY ? SY : EY;
                                                        var StandradTooch = ParamsConfigData.StandardScrewList.Find(item => item.Dimension - 0.02 <= PDim
                                                        && PDim <= item.Dimension + 0.02)?.ScrewDepth;
                                                        //找到牙穿过的最近的板(面板螺丝的的牙是从上往下穿的)
                                                        int NearBoardIndex = tempSectionList.FindIndex(item => item.BottomLine.UseStartPoint.Y < ToochCompY);
                                                        //假如只穿了一件
                                                        if (NearBoardIndex != 0)
                                                        {
                                                            List<BoardSectionItem> ThroughBoardList = tempSectionList.GetRange(0, NearBoardIndex);
                                                            ThroughPlateH = ThroughBoardList.Sum(item => item.PlateThick);
                                                            ToochY = Math.Round(ThroughBoardList[ThroughBoardList.Count - 1].BottomLine.UseStartPoint.Y - ToochCompY, 0);
                                                        }
                                                        else
                                                            //面板螺丝起码穿过面板
                                                            ThroughPlateH = tempSectionList[0].PlateThick;

                                                        //量出来的牙深比标准深，取标准值  if牙深比标准浅 取客图尺寸
                                                        //if (StandradTooch != null)
                                                        //    if (Convert.ToDecimal(ToochY) > StandradTooch)
                                                        //        ToochY = (double)StandradTooch;

                                                        double MoreThanBoardH = 0.0;
                                                        if (PDim < 20)
                                                            MoreThanBoardH = 5;
                                                        else
                                                            MoreThanBoardH = 10;

                                                        SingleItem SItem = new SingleItem();
                                                        SItem.TDPosType = InBoardPosType.BoardUp;
                                                        SItem.ItemNameType = DItemNameType.TopPanelScrew;
                                                        double PMaxY = CTempPList[k].InfoList.Select(item => item.LLine).Max(item => item.StartPoint.CustomerPoint.Y);
                                                        double PMinY = CTempPList[k].InfoList.Select(item => item.LLine).Min(item => item.EndPoint.CustomerPoint.Y);
                                                        SItem.PeakY = PMaxY;
                                                        SItem.NadirY = PMinY;
                                                        SItem.RealScrewH = Math.Round(PMaxY - PMinY, 0);
                                                        SItem.TheoryScrewH =ComputedUtils. RepScrewItemLRule(ThroughPlateH + MoreThanBoardH);
                                                        int RBeginIndex = AssemblyShareData.ASectionList.FindIndex(item => item.OverheadLine.StartPoint.CustomerPoint.Y <= PMaxY);
                                                        int REndIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BottomLine.StartPoint.CustomerPoint.Y <= PMinY);
                                                        //面板螺丝所在的区域
                                                        List<BoardSectionItem> InBoardList = AssemblyShareData.ASectionList.GetRange(RBeginIndex, REndIndex - RBeginIndex + 1);
                                                        if (InBoardList.Count > 0)
                                                        {
                                                            BoardSectionItem LastBoard = InBoardList[InBoardList.Count - 1];
                                                            if (Math.Round(PMinY, 0) > Math.Round(LastBoard.BottomLine.StartPoint.CustomerPoint.Y, 0))
                                                            {
                                                                SItem.ToochInfo.ExistTheTip = true;
                                                                SItem.ToochInfo.BlindToochH = ToochY;
                                                                SItem.BlindHoleBoard = LastBoard;
                                                                InBoardList.RemoveAt(InBoardList.Count - 1);
                                                            }
                                                        }
                                                        //托位 默认 第一个
                                                        if (InBoardList.Count > 0)
                                                        {
                                                            SItem.TDBoard = InBoardList[0];
                                                            InBoardList.RemoveAt(0);
                                                            if (InBoardList.Count > 0)
                                                                SItem.ScrewDimThroughHBList = InBoardList;
                                                        }
                                                        SItem.Dim = CTempPList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.Dim).Select(item => item.XLength).First();
                                                        SItem.TD = (int)CTempPList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD).Select(item => item.XLength).First();
                                                        //托位深度
                                                        double TH = CTempPList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD).Select(item => item.YLength).Distinct().Max();
                                                        SItem.TH = Convert.ToDecimal(TH);
                                                        SItem.TVCPX = CTempPList[k].CenterPoint.CustomerPoint.X;
                                                        SItem.MatchScrewHole = CTempPList[k].MatchScrewHole;
                                                        SItem.RelScrewHoleList = CTempPList[k].RelScrewHoleList;
                                                        SItem.ItemNum = SItem.RelScrewHoleList.Count;
                                                        RefHoleCenterSplitInfo SInfo = TranRefCHoleData(SItem.ItemNameType, SItem.RelScrewHoleList);
                                                        SItem.HSplitInfo = SInfo;
                                                        SItem.ItemCode = "TopPanelScrew";
                                                        wantAddTpScrewList.Add(SItem);
                                                    }
                                                }
                                            }
                                        }
                                        //Dup
                                        if (wantAddTpScrewList.Count > 0)
                                        {
                                            List<SingleItem> resList = new List<SingleItem>();
                                            resList.Add(wantAddTpScrewList[0]);
                                            if (wantAddTpScrewList.Count > 1)
                                            {
                                                for (int i = 1; i < wantAddTpScrewList.Count; i++)
                                                {
                                                    Boolean NoSameFlag = resList.FindIndex(item => CU.JudgeDupRItem(item, wantAddTpScrewList[i])) == -1;
                                                    if (NoSameFlag)
                                                        resList.Add(wantAddTpScrewList[i]);
                                                }
                                            }
                                            if (resList.Count > 0)
                                                ShareItemData.ItemList.AddRange(resList);

                                        }
                                        //没有尖 未测试
                                        if (!CTempPList[k].ToochInfo.ExistTheTip)
                                        {
                                            SingleItem SItem = new SingleItem();
                                            SItem.ItemNameType = DItemNameType.TopPanelScrew;
                                            double PMaxY = CTempPList[k].InfoList.Select(item => item.LLine).Max(item => item.StartPoint.CustomerPoint.Y);
                                            double PMinY = CTempPList[k].InfoList.Select(item => item.LLine).Min(item => item.EndPoint.CustomerPoint.Y);
                                            SItem.RealScrewH = Math.Round(PMaxY - PMinY, 0);
                                            int RBeginIndex = AssemblyShareData.ASectionList.FindIndex(item => item.OverheadLine.StartPoint.CustomerPoint.Y <= PMaxY);
                                            int REndIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BottomLine.EndPoint.CustomerPoint.Y <= PMinY);
                                            //托位深度
                                            double TH = CTempPList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD).Select(item => item.YLength).Distinct().Max();
                                            //面板螺丝所在的区域
                                            List<BoardSectionItem> InBoardList = AssemblyShareData.ASectionList.GetRange(RBeginIndex, REndIndex - RBeginIndex + 1);
                                            if (InBoardList.Count > 0)
                                            {
                                                BoardSectionItem LastBoard = InBoardList[InBoardList.Count - 1];
                                                if (Math.Round(PMinY, 0) > Math.Round(LastBoard.BottomLine.UseStartPoint.Y, 0))
                                                {
                                                    double ToochY = Math.Round(LastBoard.OverheadLine.UseStartPoint.Y - PMinY, 0);
                                                    SItem.ToochInfo.BlindToochH = ToochY;
                                                    SItem.BlindHoleBoard = LastBoard;
                                                    InBoardList.RemoveAt(InBoardList.Count - 1);
                                                }
                                            }
                                            double ThroughPlateH = InBoardList.Sum(item => item.PlateThick);
                                            double MoreThanBoardH = 0.0;
                                            if (PDim < 20)
                                                MoreThanBoardH = 5;
                                            else
                                                MoreThanBoardH = 10;
                                            SItem.TheoryScrewH = ComputedUtils.RepScrewItemLRule(ThroughPlateH + MoreThanBoardH);
                                            SItem.Dim = CTempPList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.Dim).Select(item => item.XLength).First();
                                            SItem.TD = Convert.ToDecimal(Math.Round(CTempPList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD).Select(item => item.XLength).First(), 0));
                                            SItem.TH = Convert.ToDecimal(Math.Round(TH, 0));
                                            SItem.TDPosType = InBoardPosType.BoardUp;
                                            //托位 默认 第一个
                                            if (InBoardList.Count > 0)
                                            {
                                                SItem.TDBoard = InBoardList[0];
                                                InBoardList.RemoveAt(0);
                                                if (InBoardList.Count > 0)
                                                    SItem.ScrewDimThroughHBList = InBoardList;
                                            }
                                            SItem.TVCPX = CTempPList[k].CenterPoint.CustomerPoint.X;
                                            SItem.MatchScrewHole = CTempPList[k].MatchScrewHole;
                                            SItem.RelScrewHoleList = CTempPList[k].RelScrewHoleList;
                                            SItem.ItemNum = SItem.RelScrewHoleList.Count;
                                            RefHoleCenterSplitInfo SInfo = TranRefCHoleData(SItem.ItemNameType, SItem.RelScrewHoleList);
                                            SItem.HSplitInfo = SInfo;
                                            SItem.ItemCode = "TopPanelScrew";
                                            CU.ScrewTransToProcessData(SItem);
                                            ShareItemData.ItemList.Add(SItem);
                                        }
                                    }

                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {

            }

        }

        //BP Screw F
        public static void RecognizeBpScrew(Dictionary<double, List<MixedCAD_Line>> AVLineYDic, Dictionary<double, List<MixedCAD_Line>> OBLineYDic)
        {
            try
            {
                //Assem View bpBoardScrew Item Part Ref X  
                double? AVRealRefX = null;
                double? AVCustomerCX = null; 
                // Result Data
                List<SingleItem> BPList = new List<SingleItem>();
                //Item Part Collection
                List<CSingleItem> CTempBPList = new List<CSingleItem>();
                //Assem bpBoardScrew Item Part V Line Collection
                List<CSinglePartItem> BPItemVList = new List<CSinglePartItem>();
                List<BoardSectionItem> NoFallerBoardList = new List<BoardSectionItem>(AssemblyShareData.ASectionList);
                NoFallerBoardList = NoFallerBoardList.FindAll(item => !item.BoardCode.Equals("epBoard")
                && !item.BoardCode.Equals("fpBoard"));
                if (StandardShareScopeItemParam.SmallSScrewDimList.Count > 0)
                {
                    List<int> DimList = StandardShareScopeItemParam.SmallSScrewDimList;
                    int LastFIndex = NoFallerBoardList.FindLastIndex(item => item.BoardCode.Equals("fangtie"));
                    List<MixedCAD_Line> BPVLines = new List<MixedCAD_Line>();
                    List<MixedCAD_Line> FToochOBLine = new List<MixedCAD_Line>();
                    BoardSectionItem StartBoard = new BoardSectionItem();
                    BoardSectionItem EndBoard = NoFallerBoardList[NoFallerBoardList.Count - 1];
                    //not pass Fangtie
                    if (LastFIndex != -1)
                        StartBoard = NoFallerBoardList[LastFIndex];
                    else
                        StartBoard = NoFallerBoardList[NoFallerBoardList.Count - 2];

                    double MaxY = Math.Round(StartBoard.OverheadLine.UseStartPoint.Y, 0);
                    double MinY = Math.Round(EndBoard.BottomLine.UseStartPoint.Y, 0);

                    List<double> FBoardVLineKeys = AVLineYDic.Keys.ToList().FindAll(item => MinY <= Math.Round(item, 0)
                    && Math.Round(item, 0) <= MaxY);
                    if (FBoardVLineKeys != null)
                        FBoardVLineKeys.ForEach(key => BPVLines.AddRange(AVLineYDic[key]));

                    List<double> fangtieOBLineKeys = OBLineYDic.Keys.ToList().FindAll(item => MinY <= Math.Round(item, 0)
                    && Math.Round(item, 0) <= MaxY);
                    if (fangtieOBLineKeys != null)
                        fangtieOBLineKeys.ForEach(key => FToochOBLine.AddRange(OBLineYDic[key]));

                    //epBoardScrew Hole
                    Boolean hasPinSF = ShareItemData.ItemList.FindIndex(item => item.ItemCode.Equals("PinBoardScrew")) != -1;
                    List<ScrewHole> CSList = (List<ScrewHole>)ConvertUtils.DeepCopyObject(HoleCandidateShareData.SmallScrewCList);
                    if (hasPinSF)
                        CSList = CSList.FindAll(item => item.fPosType == FPosType.L || item.fPosType == FPosType.R);
                    ComputedUtils.SwitchTVHoleCoorType(CSList);
                    if (BPVLines.Count > 0 && CSList.Count > 0)
                    {
                        ScrewHole targetHole = CSList[0];
                        List<double> SSXList = CSList.Select(item => item.UseCenterPoint.X).Distinct().ToList();
                        for (int i = 0; i < BPVLines.Count - 1; i++)
                        {
                            for (int j = 1; j < BPVLines.Count; j++)
                            {
                                if (j > i)
                                {
                                    for (int k = 0; k < SSXList.Count; k++)
                                    {
                                        double TempDim = Math.Round(Math.Abs(BPVLines[i].StartPoint.UsePoint.X - BPVLines[j].StartPoint.UsePoint.X), 2);
                                        double TwoLineSplitAgvCX = Math.Round((BPVLines[i].StartPoint.UsePoint.X + BPVLines[j].StartPoint.UsePoint.X) / 2, 1);
                                        double TwoLineCustomerAgvCX = Math.Round((BPVLines[i].StartPoint.CustomerPoint.X + BPVLines[j].StartPoint.CustomerPoint.X) / 2, 1);
                                        double TargetCenterX = Math.Round(SSXList[k], 1);
                                        double LX = TargetCenterX - 5;
                                        double RX = TargetCenterX + 5;
                                        if (LX <= TwoLineSplitAgvCX && TwoLineSplitAgvCX <= RX)
                                        {
                                            CSinglePartItem RPItem = new CSinglePartItem();
                                            if (CSList[k].Dim - 0.02 <= TempDim && TempDim <= CSList[k].Dim + 0.02)
                                            {
                                                //Dim
                                                RPItem.ItemType = ItemPartCodeType.Dim;
                                                RPItem.LLine = BPVLines[i];
                                                RPItem.RLine = BPVLines[j];
                                                RPItem.XLength = TempDim;
                                                RPItem.YLength = Math.Round(Math.Abs(BPVLines[i].StartPoint.CustomerPoint.Y - BPVLines[i].EndPoint.CustomerPoint.Y), 0);
                                                RPItem.TVCPX = TargetCenterX;
                                                RPItem.AVSplitCX = TwoLineSplitAgvCX;
                                                RPItem.AVCustomerCX = TwoLineCustomerAgvCX;
                                                RPItem.MatchScrewHole = CSList[k];
                                                BPItemVList.Add(RPItem);
                                            }
                                            if (CSList[k].TD - 1 <= TempDim && TempDim <= CSList[k].TD + 1)
                                            {
                                                //TD
                                                RPItem.ItemType = ItemPartCodeType.TD;
                                                RPItem.LLine = BPVLines[i];
                                                RPItem.RLine = BPVLines[j];
                                                RPItem.XLength = TempDim;
                                                RPItem.YLength = Math.Round(Math.Abs(BPVLines[i].StartPoint.CustomerPoint.Y - BPVLines[i].EndPoint.CustomerPoint.Y), 0);
                                                RPItem.TVCPX = TargetCenterX;
                                                RPItem.AVSplitCX = TwoLineSplitAgvCX;
                                                RPItem.AVCustomerCX = TwoLineCustomerAgvCX;
                                                RPItem.MatchScrewHole = CSList[k];
                                                BPItemVList.Add(RPItem);
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        //By Dim
                        List<CSinglePartItem> DimPartList = BPItemVList.FindAll(item => item.ItemType == ItemPartCodeType.Dim).ToList();
                        List<CSinglePartItem> TDPartList = BPItemVList.FindAll(item => item.ItemType == ItemPartCodeType.TD).ToList();
                        if (hasPinSF)
                        {
                            DimPartList = DimPartList.FindAll(item => item.AVSplitCX < FangtieShareData.FLXInfo.SplitX || item.AVSplitCX > FangtieShareData.FRXInfo.SplitX);
                            TDPartList = TDPartList.FindAll(item => item.AVSplitCX < FangtieShareData.FLXInfo.SplitX || item.AVSplitCX > FangtieShareData.FRXInfo.SplitX);
                        }
                        DimPartList = DimPartList.Distinct(new CSinglePartItemComparer()).ToList();
                        TDPartList = TDPartList.Distinct(new CSinglePartItemComparer()).ToList();
                        if (DimPartList.Count > 0)
                        {
                            DimPartList = DimPartList.FindAll(item => CU.JudgeTwoYLineNoTooOverDis(item.LLine, item.RLine));
                            AVRealRefX = CU.FindItemAVSplitCX(DimPartList);
                            AVCustomerCX = CU.FindItemAVCustomerCX(DimPartList);
                            TDPartList = TDPartList.FindAll(item => item.AVSplitCX == AVRealRefX).ToList();
                            BPItemVList.AddRange(DimPartList);
                            BPItemVList.AddRange(TDPartList);
                        }

                        //Merge Tidy Up
                        if (BPItemVList.Count > 0)
                        {
                            var GroupByList = BPItemVList.GroupBy(item => item.AVSplitCX);
                            foreach (var Item in GroupByList)
                            {
                                List<CSinglePartItem> ItemPartList = Item.ToList();
                                CSingleItem CItem = new CSingleItem();
                                CItem.CenterPoint.CustomerPoint.X = Item.Key;
                                for (int i = 0; i < ItemPartList.Count; i++)
                                {
                                    CItem.MatchScrewHole = ItemPartList[i].MatchScrewHole;
                                    CItem.InfoList.Add(ItemPartList[i]);
                                }
                                CTempBPList.Add(CItem);
                            }
                        }

                        //Exclude
                        CTempBPList = CTempBPList.FindAll(item => item.InfoList.Select(info => info.ItemType).Distinct().ToList().Count > 1);
                        CTempBPList = CTempBPList.FindAll(item => CU.JudgeBpScrewTDInBpBoard(item));

                        if (CTempBPList.Count > 0)
                        {
                            double PMaxY = CTempBPList.First().InfoList.Select(item => item.LLine).Max(item => item.StartPoint.CustomerPoint.Y);
                            double PMinY = CTempBPList.First().InfoList.Select(item => item.LLine).Min(item => item.EndPoint.CustomerPoint.Y);
                            int RBeginIndex = NoFallerBoardList.FindLastIndex(item => item.OverheadLine.StartPoint.CustomerPoint.Y >= PMaxY);
                            int REndIndex = NoFallerBoardList.FindIndex(item => item.BottomLine.EndPoint.CustomerPoint.Y <= PMinY);
                            List<BoardSectionItem> InBoardList = NoFallerBoardList.GetRange(RBeginIndex, REndIndex - RBeginIndex + 1);

                            for (int i = 0; i < CTempBPList.Count; i++)
                            {
                                CTempBPList[i].RelScrewHoleList = CSList.FindAll(item =>
                                (CTempBPList[i].MatchScrewHole.Dim - 0.01 <= item.Dim && item.Dim <= CTempBPList[i].MatchScrewHole.Dim + 0.01)
                                &&
                                (CTempBPList[i].MatchScrewHole.TD - 0.01 <= item.TD && item.TD <= CTempBPList[i].MatchScrewHole.TD + 0.01));
                            }

                            for (int k = 0; k < CTempBPList.Count; k++)
                            {
                                List<CSinglePartItem> CSDimList = CTempBPList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.Dim);
                                CSDimList = CSDimList.FindAll(item => item.ItemType == ItemPartCodeType.Dim);
                                if (CSDimList.Count > 0)
                                {
                                    double? DimCenterX = null;
                                    //Dim X Estimated Value
                                    double PDim = CSDimList.Select(item => item.XLength).Distinct().Min();
                                    DimCenterX = CSDimList.Select(item => item.TVCPX).Distinct().First();
                                    //面板螺丝 钻孔
                                    if(DimCenterX != null)
                                    {
                                        for (int i = 0; i < FToochOBLine.Count - 1; i++)
                                        {
                                            for (int j = 1; j < FToochOBLine.Count; j++)
                                            {
                                                if (j > i)
                                                {
                                                    double? ToothX = JudgeTwoObliqueTooth(FToochOBLine[i], FToochOBLine[j]);
                                                    Boolean InCenterLineFlag = false;
                                                    if (ToothX != null)
                                                    {
                                                        Boolean F1 = (double)ToothX - 1 <= DimCenterX;
                                                        Boolean F2 = DimCenterX <= (double)ToothX + 1;
                                                        InCenterLineFlag = F1 && F2;
                                                    }
                                                    if (InCenterLineFlag && ToothX != null)
                                                    {
                                                        //客图 盲牙 孔深
                                                        double ToochBlindY = 0;
                                                        //穿过的板厚
                                                        double ThroughPlateH = 0;
                                                        double SY = FToochOBLine[i].StartPoint.CustomerPoint.Y;
                                                        double EY = FToochOBLine[i].EndPoint.CustomerPoint.Y;

                                                        //完整牙Y坐标
                                                        double ToochCompY = SY > EY ? SY : EY;
                                                        ToochBlindY = Math.Round(ToochCompY - InBoardList.First().BottomLine.EndPoint.CustomerPoint.Y,1);
                                                        var StandradTooch = ParamsConfigData.StandardScrewList.Find(item => item.Dimension - 0.02 <= PDim
                                                        && PDim <= item.Dimension + 0.02)?.ScrewDepth;
                                                        var StandradBlind = ParamsConfigData.StandardScrewList.Find(item => item.Dimension - 0.02 <= PDim
                                                        && PDim <= item.Dimension + 0.02)?.BlindDepth;
                                                        double MoreThanBoardH = 0.0;
                                                        if (PDim < 20)
                                                            MoreThanBoardH = 5;
                                                        else
                                                            MoreThanBoardH = 10;

                                                        SingleItem SItem = new SingleItem();
                                                        SItem.ItemNameType = DItemNameType.BottomPanelScrew;
                                                        List<CSinglePartItem> FRefDimList = CTempBPList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.Dim);
                                                        if (FRefDimList.Count > 0)
                                                        {
                                                            double PLMaxY = FRefDimList.Select(item => item.LLine).Max(item => item.StartPoint.CustomerPoint.Y);
                                                            double PRMaxY = FRefDimList.Select(item => item.RLine).Max(item => item.StartPoint.CustomerPoint.Y);
                                                            double PLMinY = FRefDimList.Select(item => item.LLine).Min(item => item.EndPoint.CustomerPoint.Y);
                                                            double PRMinY = FRefDimList.Select(item => item.RLine).Min(item => item.EndPoint.CustomerPoint.Y);
                                                            PMaxY = PLMaxY > PRMaxY ? PLMaxY : PRMaxY;
                                                            PMinY = PLMinY < PRMinY ? PLMinY : PRMinY;
                                                            SItem.PeakY = PMaxY;
                                                            SItem.NadirY = PMinY;
                                                            SItem.RealScrewH = Math.Round(PMaxY - PMinY, 0);
                                                        }
                                                        CTempBPList[k].ToochInfo.ExistTheTip = true;
                                                        SItem.ToochInfo.ExistTheTip = true;
                                                        SItem.ToochInfo.BlindToochH = ToochBlindY;
                                                        SItem.BlindHoleBoard = InBoardList.First();
                                                        InBoardList.RemoveAt(0);
                                                        SItem.TheoryScrewH = InBoardList.Sum(item => item.PlateThick) + MoreThanBoardH;
                                                        SItem.TheoryScrewH = ComputedUtils.RepScrewItemLRule(SItem.TheoryScrewH);
                                                        SItem.TDPosType = InBoardPosType.BoardDown;
                                                        if (InBoardList.Count > 0)
                                                        {
                                                            SItem.TDBoard = InBoardList[InBoardList.Count - 1];
                                                            InBoardList.RemoveAt(InBoardList.Count - 1);
                                                            if (InBoardList.Count > 0)
                                                                SItem.ScrewDimThroughHBList = InBoardList;
                                                        }
                                                        SItem.Dim = CTempBPList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.Dim).Select(item => item.XLength).First();
                                                        SItem.TD = (int)CTempBPList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD).Select(item => item.XLength).First();
                                                        //托位深度
                                                        double TH = CTempBPList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD).Select(item => item.YLength).Distinct().Max();
                                                        SItem.TH = Convert.ToDecimal(TH);
                                                        SItem.TVCPX = CTempBPList[k].CenterPoint.CustomerPoint.X;
                                                        SItem.AVCustomerCX = (double)AVCustomerCX;
                                                        SItem.MatchScrewHole = CTempBPList[k].MatchScrewHole;
                                                        SItem.RelScrewHoleList = CTempBPList[k].RelScrewHoleList;
                                                        SItem.ItemNum = SItem.RelScrewHoleList.Count;
                                                        RefHoleCenterSplitInfo SInfo = TranRefCHoleData(SItem.ItemNameType, SItem.RelScrewHoleList);
                                                        SItem.HSplitInfo = SInfo;
                                                        SItem.ItemCode = "BottomPanelScrew";
                                                        CU.ScrewTransToProcessData(SItem);
                                                        ShareItemData.ItemList.Add(SItem);
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    if (!CTempBPList[k].ToochInfo.ExistTheTip)
                                    {
                                        SingleItem SItem = new SingleItem();
                                        SItem.ItemNameType = DItemNameType.BottomPanelScrew;
                                        SItem.PeakY = PMaxY;
                                        SItem.NadirY = PMinY;
                                        SItem.RealScrewH = Math.Round(PMaxY - PMinY, 0);
                                        double MoreThanBoardH = 0.0;
                                        if (PDim < 20)
                                            MoreThanBoardH = 5;
                                        else
                                            MoreThanBoardH = 10;
                                        //computed Tooch H By Formula
                                        if (Math.Round(PMaxY, 0) > Math.Round(InBoardList[0].BottomLine.StartPoint.CustomerPoint.Y, 0))
                                        {
                                            SItem.BlindHoleBoard = InBoardList[0];
                                            InBoardList.RemoveAt(0);
                                            SItem.TheoryScrewH = InBoardList.Sum(item => item.PlateThick) + MoreThanBoardH;
                                            SItem.TheoryScrewH = ComputedUtils.RepScrewItemLRule(SItem.TheoryScrewH);
                                            SItem.ToochInfo.BlindToochH = SItem.TheoryScrewH;
                                        }
                                        //Default TD Pos
                                        SItem.TDPosType = InBoardPosType.BoardDown;
                                        if (InBoardList.Count > 0)
                                        {
                                            SItem.TDBoard = InBoardList[InBoardList.Count - 1];
                                            InBoardList.RemoveAt(InBoardList.Count - 1);
                                            if (InBoardList.Count > 0)
                                                SItem.ScrewDimThroughHBList = InBoardList;
                                        }
                                        SItem.Dim = CTempBPList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.Dim).Select(item => item.XLength).First();
                                        SItem.TD = Convert.ToDecimal(Math.Round(CTempBPList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD).Select(item => item.XLength).First(), 0));
                                        double TH = CTempBPList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD).Select(item => item.YLength).Distinct().Max();
                                        SItem.TH = Convert.ToDecimal(TH);
                                        SItem.TVCPX = CTempBPList[k].CenterPoint.CustomerPoint.X;
                                        SItem.MatchScrewHole = CTempBPList[k].MatchScrewHole;
                                        SItem.RelScrewHoleList = CTempBPList[k].RelScrewHoleList;
                                        SItem.ItemNum = SItem.RelScrewHoleList.Count;
                                        RefHoleCenterSplitInfo SInfo = TranRefCHoleData(SItem.ItemNameType, SItem.RelScrewHoleList);
                                        SItem.HSplitInfo = SInfo;
                                        SItem.ItemCode = "BottomPanelScrew";
                                        CU.ScrewTransToProcessData(SItem);
                                        ShareItemData.ItemList.Add(SItem);
                                    }
                                    
                                }

                            }
                        }

                    }
                }
            }
            catch (Exception ex)
            {
            }
        }

        //针板螺丝
        public static void RecognizeFallerScrew(string Strategy, 
            Dictionary<double, List<MixedCAD_Line>> AVLineYDic,List<MixedCAD_Line> ACenterLineList)
        {
            try
            {
                //针板零件集合
                List<CSingleItem> CTempFList = new List<CSingleItem>();
                //组装图上 针板各部位竖线集合
                List<CSinglePartItem> FItemVList = new List<CSinglePartItem>();

                //非方铁
                List<BoardSectionItem> NoFangtieBSList = new List<BoardSectionItem>(AssemblyShareData.ASectionList);
                NoFangtieBSList = NoFangtieBSList.FindAll(item => !item.BoardCode.Equals("fangtie"));

                int fpBoardCount = NoFangtieBSList.FindAll(item => item.BoardCode.Equals("fpBoard")).Count;
                int epBoardCount = NoFangtieBSList.FindAll(item => item.BoardCode.Equals("epBoard")).Count;
                //第一块上 最后一块下针板
                int fpBoardIndex = NoFangtieBSList.FindIndex(item => item.BoardCode.Equals("fpBoard"));
                int epBoardLastIndex = NoFangtieBSList.FindLastIndex(item => item.BoardCode.Equals("epBoard"));

                //上下针板集合 
                int PerfpBoardIndex = fpBoardIndex - 1;
                List<BoardSectionItem> fpepList = NoFangtieBSList.GetRange(PerfpBoardIndex, epBoardLastIndex - PerfpBoardIndex + 1);

                double MaxY = Math.Round(NoFangtieBSList[fpBoardIndex].OverheadLine.UseStartPoint.Y, 0);
                double MinY = Math.Round(NoFangtieBSList[epBoardLastIndex].BottomLine.UseStartPoint.Y, 0);
                double NOFLX = Math.Round(NoFangtieBSList[fpBoardIndex].BottomLine.UseStartPoint.X, 0);
                double NOFRX = Math.Round(NoFangtieBSList[fpBoardIndex].BottomLine.UseEndPoint.X, 0);
                //客户来图有时候会把针板螺丝直径画出一些 
                MaxY += 10;
                List<MixedCAD_Line> FVLines = new List<MixedCAD_Line>();
                List<double> fpBoardVLineKeys = AVLineYDic.Keys.ToList().FindAll(item => MinY <= Math.Round(item, 0) && Math.Round(item, 0) <= MaxY);
                if (fpBoardVLineKeys != null)
                    fpBoardVLineKeys.ForEach(key => FVLines.AddRange(AVLineYDic[key]));

                FVLines = FVLines.FindAll(item => MinY <= Math.Round(item.StartPoint.UsePoint.Y, 0) && Math.Round(item.StartPoint.UsePoint.Y, 0) <= MaxY);
                FVLines = FVLines.FindAll(item => NOFLX <= item.StartPoint.UsePoint.X && item.StartPoint.UsePoint.X <= NOFRX);

                List<ScrewHole> FList = HoleCandidateShareData.FallerScrewCList;
                ComputedUtils.SwitchTVHoleCoorType(FList);
                if (FVLines.Count > 0 && FList.Count > 0)
                {
                    if (Strategy.Equals("PLANA"))
                    {
                        for (int i = 0; i < FVLines.Count - 1; i++)
                        {
                            for (int j = 1; j < FVLines.Count; j++)
                            {
                               if (j > i)
                               {
                                    for (int k = 0; k < FList.Count; k++)
                                {
                                    double TempDim = Math.Round(Math.Abs(FVLines[i].StartPoint.UsePoint.X - FVLines[j].StartPoint.UsePoint.X), 2);
                                    //近似中心对称 计算误差在+- 0.2
                                    double TwoLineSplitAgvCX = Math.Round((FVLines[i].StartPoint.UsePoint.X + FVLines[j].StartPoint.UsePoint.X) / 2, 1);
                                    double TargetCenterX = Math.Round(FList[k].UseCenterPoint.X, 1);
                                    if (TargetCenterX - 0.2 <= TwoLineSplitAgvCX && TwoLineSplitAgvCX <= TargetCenterX + 0.2)
                                    {
                                        CSinglePartItem FItem = new CSinglePartItem();
                                        if (FList[k].Dim - 0.02 <= TempDim && TempDim <= FList[k].Dim + 0.02)
                                        {
                                            FItem.ItemType = ItemPartCodeType.Dim;
                                            FItem.LLine = FVLines[i];
                                            FItem.RLine = FVLines[j];
                                            FItem.XLength = TempDim;
                                            FItem.YLength = Math.Round(Math.Abs(FVLines[i].StartPoint.CustomerPoint.Y - FVLines[i].EndPoint.CustomerPoint.Y), 0);
                                            FItem.TVCPX = TargetCenterX;
                                            FItem.MatchScrewHole = FList[k];
                                            FItemVList.Add(FItem);
                                        }
                                        if (FList[k].TD - 1 <= TempDim && TempDim <= FList[k].TD + 1)
                                        {
                                            FItem.ItemType = ItemPartCodeType.TD;
                                            FItem.LLine = FVLines[i];
                                            FItem.RLine = FVLines[j];
                                            FItem.XLength = TempDim;
                                            FItem.YLength = Math.Round(Math.Abs(FVLines[i].StartPoint.CustomerPoint.Y - FVLines[i].EndPoint.CustomerPoint.Y), 0);
                                            FItem.TVCPX = TargetCenterX;
                                            FItem.MatchScrewHole = FList[k];
                                            FItemVList.Add(FItem);
                                        }
                                    
                                    }
                                }
                               }
                            }
                        }
                    }

                    if (Strategy.Equals("PLANB"))
                    {
                        double? epfpScrewCLX = GetEPFPScrewCLX(ACenterLineList);
                        ScrewHole refHoleItem = FList[0];
                        if(epfpScrewCLX != null)
                        {
                            //针板螺丝中心线 + -5
                            double TargetCenterX = Math.Round((double)epfpScrewCLX, 1);
                            double diffValue = 7;
                            double LX = TargetCenterX - diffValue;
                            double RX = TargetCenterX + diffValue;
                            for (int i = 0; i < FVLines.Count - 1; i++)
                            {
                                for (int j = 1; j < FVLines.Count; j++)
                                {
                                    if (j > i)
                                    {
                                        double TempDim = Math.Round(Math.Abs(FVLines[i].StartPoint.UsePoint.X - FVLines[j].StartPoint.UsePoint.X), 2);
                                        double TwoLineSplitAgvCX = Math.Round((FVLines[i].StartPoint.UsePoint.X + FVLines[j].StartPoint.UsePoint.X) / 2, 1);
                                        if (LX <= TwoLineSplitAgvCX && TwoLineSplitAgvCX <= RX)
                                        {
                                            //大致归为针板的部位
                                            CSinglePartItem FItem = new CSinglePartItem();
                                            if (refHoleItem.Dim - 0.02 <= TempDim && TempDim <= refHoleItem.Dim + 0.02)
                                            {
                                                FItem.ItemType = ItemPartCodeType.Dim;
                                                FItem.LLine = FVLines[i];
                                                FItem.RLine = FVLines[j];
                                                FItem.XLength = TempDim;
                                                FItem.YLength = Math.Round(Math.Abs(FVLines[i].StartPoint.CustomerPoint.Y - FVLines[i].EndPoint.CustomerPoint.Y), 0);
                                                FItem.TVCPX = TargetCenterX;
                                                FItem.MatchScrewHole = refHoleItem;
                                                FItemVList.Add(FItem);
                                            }
                                            if (refHoleItem.TD - 1 <= TempDim && TempDim <= refHoleItem.TD + 1)
                                            {
                                                FItem.ItemType = ItemPartCodeType.TD;
                                                FItem.LLine = FVLines[i];
                                                FItem.RLine = FVLines[j];
                                                FItem.XLength = TempDim;
                                                FItem.YLength = Math.Round(Math.Abs(FVLines[i].StartPoint.CustomerPoint.Y - FVLines[i].EndPoint.CustomerPoint.Y), 0);
                                                FItem.TVCPX = TargetCenterX;
                                                FItem.MatchScrewHole = refHoleItem;
                                                FItemVList.Add(FItem);
                                            }

                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (FItemVList.Count > 0)
                    {
                        List<CSinglePartItem> resList = new List<CSinglePartItem>();
                        resList.Add(FItemVList[0]);
                        if (FItemVList.Count > 1)
                        {
                            for (int i = 1; i < FItemVList.Count; i++)
                            {
                                Boolean NoSameFlag = resList.FindIndex(item => CU.JudgeEqualItemPart(item, FItemVList[i])) == -1;
                                if (NoSameFlag)
                                    resList.Add(FItemVList[i]);
                            }
                        }
                        FItemVList = resList;
                    }
                    //合并针板螺丝
                    if (FItemVList.Count > 0)
                    {
                        var GroupByList = FItemVList.GroupBy(item => item.TVCPX);
                        foreach (var Item in GroupByList)
                        {
                            List<CSinglePartItem> ItemPartList = Item.ToList();
                            CSingleItem CItem = new CSingleItem();
                            CItem.CenterPoint.CustomerPoint.X = Item.Key;
                            for (int i = 0; i < ItemPartList.Count; i++)
                            {
                                CItem.MatchScrewHole = ItemPartList[i].MatchScrewHole;
                                CItem.InfoList.Add(ItemPartList[i]);
                            }
                            CTempFList.Add(CItem);
                        }
                    }
                    //收集针板螺丝数据
                    if (CTempFList.Count > 0)
                    {
                        BoardSectionItem epBoard = AssemblyShareData.ASectionList.FindLast(item => item.BoardCode.Equals("epBoard"));
                        double epLX = epBoard.OverheadLine.StartPoint.TransSplitPoint.X;
                        double epRX = epBoard.OverheadLine.EndPoint.TransSplitPoint.X;
                        for (int i = 0; i < CTempFList.Count; i++)
                        {
                            CTempFList[i].RelScrewHoleList = FList.FindAll(item =>
                               (CTempFList[i].MatchScrewHole.Dim - 0.01 <= item.Dim && item.Dim <= CTempFList[i].MatchScrewHole.Dim + 0.01)
                               &&
                               (CTempFList[i].MatchScrewHole.TD - 0.01 <= item.TD && item.TD <= CTempFList[i].MatchScrewHole.TD + 0.01));

                            CTempFList[i].RelScrewHoleList = CTempFList[i].RelScrewHoleList.FindAll(item => epLX < item.CenterPoint.TransSplitPoint.X && item.CenterPoint.TransSplitPoint.X < epRX);
                        }
                        // KKTOEDIT
                        for (int i = 0; i < CTempFList.Count; i++)
                        {
                            if (CTempFList[i].InfoList.Count > 0)
                            {
                                double? FDim = CTempFList[i].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.Dim)?.Select(item => item.XLength).Distinct().Min();
                                SingleItem SItem = new SingleItem();
                                SItem.ItemNameType = DItemNameType.PinBoardScrew;
                                //除去方铁的干扰
                                List<BoardSectionItem> NoFangtieList = new List<BoardSectionItem>(AssemblyShareData.ASectionList);
                                NoFangtieList = NoFangtieList.FindAll(item => !item.BoardCode.Equals("fangtie"));
                                double RPMaxY = CTempFList[i].InfoList.Select(item => item.LLine).Max(item => item.StartPoint.CustomerPoint.Y);
                                //有时候针板螺丝会画到离空那里 这里有个误差范围
                                double ErrorRPMaxY = RPMaxY + 10;
                                double RPMinY = CTempFList[i].InfoList.Select(item => item.LLine).Min(item => item.EndPoint.CustomerPoint.Y);
                                int RPBeginIndex = NoFangtieList.FindIndex(item => item.BottomLine.StartPoint.CustomerPoint.Y <= ErrorRPMaxY);
                                int RPEndIndex = NoFangtieList.FindIndex(item => item.BottomLine.StartPoint.CustomerPoint.Y <= RPMinY);
                                //针板螺丝螺丝所在的区域
                                List<BoardSectionItem> InBoardList = NoFangtieList.GetRange(RPBeginIndex, RPEndIndex - RPBeginIndex + 1);
                                double MoreThanBoardH = 0.0;
                                if (FDim != null)
                                {
                                    if (FDim < 20)
                                        MoreThanBoardH = 5;
                                    else
                                        MoreThanBoardH = 10;
                                }
                                //托位默认在最后一块板上
                                if (InBoardList.Count > 0)
                                {
                                    SItem.TDBoard = InBoardList[InBoardList.Count - 1];
                                    InBoardList.RemoveAt(InBoardList.Count - 1);
                                    SItem.TheoryScrewH = ComputedUtils.RepScrewItemLRule(SItem.TDBoard.PlateThick + MoreThanBoardH);
                                }

                                if(InBoardList.Count > 0)
                                    SItem.ScrewDimThroughHBList.Add(InBoardList.First());

                                SItem.PeakY = RPMaxY;
                                SItem.NadirY = RPMinY;
                                SItem.TDPosType = InBoardPosType.BoardDown;
                                SItem.RealH = Convert.ToInt32(Math.Round(RPMaxY - RPMinY, 0));
                                SItem.Dim = CTempFList[i].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.Dim).Select(item => item.XLength).First();
                                SItem.Dim = Math.Round(SItem.Dim, 0);
                                SItem.TD = (int)CTempFList[i].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD).Select(item => item.XLength).First();
                                double TH = CTempFList[i].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD).Select(item => item.YLength).Distinct().Max();
                                SItem.TH = Convert.ToDecimal(TH);
                                SItem.TVCPX = CTempFList[i].CenterPoint.CustomerPoint.X;
                                SItem.MatchScrewHole = CTempFList[i].MatchScrewHole;
                                SItem.RelScrewHoleList = CTempFList[i].RelScrewHoleList;
                                SItem.ItemNum = SItem.RelScrewHoleList.Count;
                                RefHoleCenterSplitInfo SInfo = TranRefCHoleData(SItem.ItemNameType, SItem.RelScrewHoleList);
                                SItem.HSplitInfo = SInfo;
                                SItem.ItemCode = "PinBoardScrew";
                                CU.ScrewTransToProcessData(SItem);
                                ShareItemData.ItemList.Add(SItem);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }

        //F
        public static int RecognizeFangtieScrew(string Strategy,Dictionary<double, List<MixedCAD_Line>> AVLineYDic, 
            Dictionary<double, List<MixedCAD_Line>> OBLineYDic, List<MixedCAD_Line> ACenterLineList)
        {
            int gpBoardEndIndex = -1;
            try
            {
                List<CSingleItem> CTempFList = new List<CSingleItem>();
                List<CSinglePartItem> FItemVList = new List<CSinglePartItem>();
                int fangtieIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("fangtie"));
                //Before Fangtie
                int PFIndex = fangtieIndex - 1; 
                int BeginBIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("bBoard"));
                if (BeginBIndex >= 0)
                {
                    BoardSectionItem PerFangtieBoardInfo = AssemblyShareData.ASectionList[PFIndex];
                    BoardSectionItem PerbBoardInfo = AssemblyShareData.ASectionList[BeginBIndex];
                    List<MixedCAD_Line> PerFVLines = new List<MixedCAD_Line>();
                    List<MixedCAD_Line> FToochOBLine = new List<MixedCAD_Line>();

                    double ToochAreaMaxY = Math.Round(PerbBoardInfo.OverheadLine.UseStartPoint.Y, 2);
                    double ToochAreaMinY = Math.Round(PerFangtieBoardInfo.BottomLine.UseStartPoint.Y, 0);
                    double bpBoardMinY = AssemblyShareData.ASectionList.Find(item => item.BoardCode.Equals("bpBoard")).BottomLine.UseEndPoint.Y;
                    List<double> fangtieVLineKeys = AVLineYDic.Keys.ToList().FindAll(item => bpBoardMinY <= Math.Round(item, 0) 
                    && Math.Round(item, 0) <= ToochAreaMaxY);
                    //Tooch Find Under bBoard
                    List<double> fangtieOBLineKeys = OBLineYDic.Keys.ToList().FindAll(item => ToochAreaMinY <= Math.Round(item, 0)
                    && Math.Round(item, 0) <= ToochAreaMaxY);

                    if (fangtieVLineKeys != null)
                        fangtieVLineKeys.ForEach(key => PerFVLines.AddRange(AVLineYDic[key]));

                    if (fangtieOBLineKeys != null)
                        fangtieOBLineKeys.ForEach(key => FToochOBLine.AddRange(OBLineYDic[key]));

                    PerFVLines = PerFVLines.FindAll(item => item.StartPoint.TransSplitPoint.X < FangtieShareData.FLXInfo.SplitX
                    || item.StartPoint.TransSplitPoint.X > FangtieShareData.FRXInfo.SplitX);
                    List<ScrewHole> FList = HoleCandidateShareData.BigScrewCList.FindAll(item =>
                    (item.CenterPoint.TransSplitPoint.X < FangtieShareData.FLXInfo.SplitX || item.CenterPoint.TransSplitPoint.X > FangtieShareData.FRXInfo.SplitX));
                    ComputedUtils.SwitchTVHoleCoorType(FList);
                    if (PerFVLines.Count > 0 && FList.Count > 0)
                    {
                        if (Strategy.Equals("PLANA"))
                        {
                            for (int i = 0; i < PerFVLines.Count - 1; i++)
                            {
                                for (int j = 1; j < PerFVLines.Count; j++)
                                {
                                    if (j > i)
                                    {
                                        for (int k = 0; k < FList.Count; k++)
                                        {
                                            double TempDim = Math.Round(Math.Abs(PerFVLines[i].StartPoint.UsePoint.X - PerFVLines[j].StartPoint.UsePoint.X), 2);
                                            double TwoLineSplitAgvCX = Math.Round((PerFVLines[i].StartPoint.UsePoint.X + PerFVLines[j].StartPoint.UsePoint.X) / 2, 1);
                                            double TargetCenterX = Math.Round(FList[k].UseCenterPoint.X, 1);
                                            if (TargetCenterX - 0.2 <= TwoLineSplitAgvCX && TwoLineSplitAgvCX <= TargetCenterX + 0.2)
                                            {
                                                CSinglePartItem PItem = new CSinglePartItem();
                                                if (FList[k].Dim - 0.02 <= TempDim && TempDim <= FList[k].Dim + 0.02)
                                                {
                                                    PItem.ItemType = ItemPartCodeType.Dim;
                                                    PItem.LLine = PerFVLines[i];
                                                    PItem.RLine = PerFVLines[j];
                                                    PItem.XLength = TempDim;
                                                    PItem.YLength = Math.Round(Math.Abs(PerFVLines[i].StartPoint.CustomerPoint.Y - PerFVLines[i].EndPoint.CustomerPoint.Y), 0);
                                                    PItem.TVCPX = TargetCenterX;
                                                    PItem.MatchScrewHole = FList[k];
                                                    FItemVList.Add(PItem);
                                                }
                                                if (FList[k].TD - 1 <= TempDim && TempDim <= FList[k].TD + 1)
                                                {
                                                    PItem.ItemType = ItemPartCodeType.TD;
                                                    PItem.LLine = PerFVLines[i];
                                                    PItem.RLine = PerFVLines[j];
                                                    PItem.XLength = TempDim;
                                                    PItem.YLength = Math.Round(Math.Abs(PerFVLines[i].StartPoint.CustomerPoint.Y - PerFVLines[i].EndPoint.CustomerPoint.Y), 0);
                                                    PItem.TVCPX = TargetCenterX;
                                                    PItem.MatchScrewHole = FList[k];
                                                    FItemVList.Add(PItem);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        
                        if (Strategy.Equals("PLANB"))
                        {
                            double? FangtieScrewCLX = GetFangtieScrewCLX(ACenterLineList);
                            ScrewHole refHoleItem = FList[0];
                            if (FangtieScrewCLX != null)
                            {
                                // 方铁螺丝中心线 +- 5
                                double TargetCenterX = Math.Round((double)FangtieScrewCLX, 1);
                                double LX = TargetCenterX - 5;
                                double RX = TargetCenterX + 5;
                                for (int i = 0; i < PerFVLines.Count - 1; i++)
                                {
                                    for (int j = 1; j < PerFVLines.Count; j++)
                                    {
                                        if (j > i)
                                        {
                                            double TempDim = Math.Round(Math.Abs(PerFVLines[i].StartPoint.UsePoint.X - PerFVLines[j].StartPoint.UsePoint.X), 2);
                                            double TwoLineSplitAgvCX = Math.Round((PerFVLines[i].StartPoint.UsePoint.X + PerFVLines[j].StartPoint.UsePoint.X) / 2, 1);
                                            if (LX <= TwoLineSplitAgvCX && TwoLineSplitAgvCX <= RX)
                                            {
                                                CSinglePartItem PItem = new CSinglePartItem();
                                                if (refHoleItem.Dim - 0.02 <= TempDim && TempDim <= refHoleItem.Dim + 0.02)
                                                {
                                                    PItem.ItemType = ItemPartCodeType.Dim;
                                                    PItem.LLine = PerFVLines[i];
                                                    PItem.RLine = PerFVLines[j];
                                                    PItem.XLength = TempDim;
                                                    PItem.YLength = Math.Round(Math.Abs(PerFVLines[i].StartPoint.CustomerPoint.Y - PerFVLines[i].EndPoint.CustomerPoint.Y), 0);
                                                    PItem.TVCPX = TargetCenterX;
                                                    PItem.MatchScrewHole = refHoleItem;
                                                    FItemVList.Add(PItem);
                                                }
                                                if (refHoleItem.TD - 1 <= TempDim && TempDim <= refHoleItem.TD + 1)
                                                {
                                                    PItem.ItemType = ItemPartCodeType.TD;
                                                    PItem.LLine = PerFVLines[i];
                                                    PItem.RLine = PerFVLines[j];
                                                    PItem.XLength = TempDim;
                                                    PItem.YLength = Math.Round(Math.Abs(PerFVLines[i].StartPoint.CustomerPoint.Y - PerFVLines[i].EndPoint.CustomerPoint.Y), 0);
                                                    PItem.TVCPX = TargetCenterX;
                                                    PItem.MatchScrewHole = refHoleItem;
                                                    FItemVList.Add(PItem);
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                        }

                        //Dis
                        if (FItemVList.Count > 0)
                        {
                            List<CSinglePartItem> resList = new List<CSinglePartItem>();
                            resList.Add(FItemVList[0]);
                            if (FItemVList.Count > 1)
                            {
                                for (int i = 1; i < FItemVList.Count; i++)
                                {
                                    Boolean NoSameFlag = resList.FindIndex(item => CU.JudgeEqualItemPart(item, FItemVList[i])) == -1;
                                    if (NoSameFlag)
                                        resList.Add(FItemVList[i]);
                                }
                            }
                            FItemVList = resList;
                        }

                        //Merge
                        if (FItemVList.Count > 0)
                        {
                            var GroupByList = FItemVList.GroupBy(item => item.TVCPX);
                            foreach (var Item in GroupByList)
                            {
                                List<CSinglePartItem> ItemPartList = Item.ToList();
                                CSingleItem CItem = new CSingleItem();
                                CItem.CenterPoint.CustomerPoint.X = Item.Key;
                                for (int i = 0; i < ItemPartList.Count; i++)
                                {
                                    CItem.MatchScrewHole = ItemPartList[i].MatchScrewHole;
                                    CItem.InfoList.Add(ItemPartList[i]);
                                }
                                CTempFList.Add(CItem);
                            }
                        }

                        CTempFList = CTempFList.FindAll(item => item.InfoList.Select(info => info.ItemType).Distinct().ToList().Count > 1);
                        if (CTempFList.Count > 0)
                        {
                            List<BoardSectionItem> NoFallerBoardList = new List<BoardSectionItem>(AssemblyShareData.ASectionList);
                            NoFallerBoardList = NoFallerBoardList.FindAll(item => !item.BoardCode.Equals("epBoard") 
                            && !item.BoardCode.Equals("fpBoard"));

                            for (int i = 0; i < CTempFList.Count; i++)
                                CTempFList[i].RelScrewHoleList = FList.FindAll(item =>
                                   (CTempFList[i].MatchScrewHole.Dim - 0.01 <= item.Dim && item.Dim <= CTempFList[i].MatchScrewHole.Dim + 0.01)
                                   &&
                                   (CTempFList[i].MatchScrewHole.TD - 0.01 <= item.TD && item.TD <= CTempFList[i].MatchScrewHole.TD + 0.01));

                            for (int k = 0; k < CTempFList.Count; k++)
                            {
                                List<CSinglePartItem> DimPartItemList = CTempFList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.Dim).ToList();
                                //大约直径
                                double? PDim = null;
                                double? DimCenterX = null;
                                if (DimPartItemList.Count > 0)
                                {
                                    PDim = DimPartItemList.Select(item => item.XLength).Distinct().First();
                                    DimCenterX = DimPartItemList.Select(item => item.TVCPX).Distinct().First();
                                }

                                if (DimCenterX != null)
                                {
                                    //识别方铁螺丝 尖
                                    for (int i = 0; i < FToochOBLine.Count - 1; i++)
                                    {
                                        for (int j = 1; j < FToochOBLine.Count; j++)
                                        {
                                            if (j > i)
                                            {
                                                double? ToothX = JudgeTwoObliqueTooth(FToochOBLine[i], FToochOBLine[j]);
                                                Boolean InCenterLineFlag = false;
                                                if (ToothX != null)
                                                {
                                                    Boolean F1 = (double)ToothX - 1 <= DimCenterX;
                                                    Boolean F2 = DimCenterX <= (double)ToothX + 1;
                                                    InCenterLineFlag = F1 && F2;
                                                }
                                                if (InCenterLineFlag && ToothX != null)
                                                {
                                                    //客户来图牙深
                                                    double ToochY = 0;
                                                    //穿过的板厚
                                                    double ThroughPlateH = 0;
                                                    //客户来图能找到牙
                                                    CTempFList[k].ToochInfo.ExistTheTip = true;
                                                    double SY = FToochOBLine[i].StartPoint.CustomerPoint.Y;
                                                    double EY = FToochOBLine[i].EndPoint.CustomerPoint.Y;

                                                    //完整牙Y坐标
                                                    double ToochCompY = SY > EY ? SY : EY;
                                                    var StandradTooch = ParamsConfigData.StandardScrewList.Find(item => item.Dimension - 0.02 <= PDim
                                                    && PDim <= item.Dimension + 0.02)?.ScrewDepth;
                                                    var StandradBlind = ParamsConfigData.StandardScrewList.Find(item => item.Dimension - 0.02 <= PDim
                                                    && PDim <= item.Dimension + 0.02)?.BlindDepth;
                                                    List<BoardSectionItem> NofpepBoardList = new List<BoardSectionItem>(AssemblyShareData.ASectionList);
                                                    NofpepBoardList = NofpepBoardList.FindAll(item => !item.BoardCode.Equals("fpBoard") && !item.BoardCode.Equals("epBoard"));
                                                    //找到所在的第一块板
                                                    int FTInBoardIndex = NofpepBoardList.FindIndex(item => item.BottomLine.StartPoint.CustomerPoint.Y < ToochCompY);
                                                    //方铁螺丝所在的区域
                                                    List<BoardSectionItem> InBoardList = new List<BoardSectionItem>();
                                                    BoardSectionItem PBNbItem = new BoardSectionItem();
                                                    if (FTInBoardIndex != -1)
                                                    {
                                                        InBoardList = NofpepBoardList.GetRange(FTInBoardIndex, NofpepBoardList.Count - FTInBoardIndex);
                                                        List<BoardSectionItem> InFList = InBoardList.FindAll(item => item.BoardCode.Equals("fangtie"));
                                                        if (InFList.Count > 0)
                                                        {
                                                            InBoardList = InBoardList.FindAll(item => !item.BoardCode.Equals("fangtie"));
                                                            InBoardList.Add(InFList[0]);
                                                            InBoardList = InBoardList.OrderBy(item => item.plateLineNo).ToList();
                                                        }
                                                        if (InBoardList.Count > 0)
                                                        {
                                                            //有钻头 默认去掉第一块板
                                                            PBNbItem = InBoardList[0];
                                                            InBoardList.RemoveAt(0);
                                                            if (InBoardList.Count > 0)
                                                            {
                                                                ThroughPlateH = InBoardList.Sum(item => item.PlateThick);
                                                                ToochY = Math.Round(ToochCompY - InBoardList[InBoardList.Count - 1].BottomLine.EndPoint.CustomerPoint.Y, 0) - ThroughPlateH;
                                                            }
                                                        }
                                                    }

                                                    //量出来的牙深比标准深，取标准值  if牙深比标准浅 取客图尺寸
                                                    //if (StandradTooch != null)
                                                    //    if (Convert.ToDecimal(ToochY) > StandradTooch)
                                                    //        ToochY = (double)StandradTooch;

                                                    double MoreThanBoardH = 0.0;
                                                    if (PDim < 20)
                                                        MoreThanBoardH = 5;
                                                    else
                                                        MoreThanBoardH = 10;

                                                    SingleItem SItem = new SingleItem();
                                                    SItem.ItemNameType = DItemNameType.SpaceBlockScrew;
                                                    List<CSinglePartItem> FRefDimList = CTempFList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.Dim);
                                                    if (FRefDimList.Count > 0)
                                                    {
                                                        double PLMaxY = FRefDimList.Select(item => item.LLine).Max(item => item.StartPoint.CustomerPoint.Y);
                                                        double PRMaxY = FRefDimList.Select(item => item.RLine).Max(item => item.StartPoint.CustomerPoint.Y);
                                                        double PLMinY = FRefDimList.Select(item => item.LLine).Min(item => item.EndPoint.CustomerPoint.Y);
                                                        double PRMinY = FRefDimList.Select(item => item.RLine).Min(item => item.EndPoint.CustomerPoint.Y);
                                                        double PMaxY = PLMaxY > PRMaxY ? PLMaxY : PRMaxY;
                                                        double PMinY = PLMinY < PRMinY ? PLMinY : PRMinY;
                                                        SItem.PeakY = PMaxY;
                                                        SItem.NadirY = PMinY;
                                                        SItem.RealScrewH = Math.Round(PMaxY - PMinY, 0);
                                                    }
                                                    SItem.ToochInfo.ExistTheTip = true;
                                                    SItem.ToochInfo.BlindToochH = ToochY;
                                                    SItem.TheoryScrewH = ComputedUtils.RepScrewItemLRule(ThroughPlateH + MoreThanBoardH);
                                                    SItem.BlindHoleBoard = PBNbItem;
                                                    gpBoardEndIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardUID.Equals(SItem.BlindHoleBoard.BoardUID));
                                                    SItem.TDPosType = InBoardPosType.BoardDown;
                                                    if (InBoardList.Count > 0)
                                                    {
                                                        SItem.TDBoard = InBoardList[InBoardList.Count - 1];
                                                        InBoardList.RemoveAt(InBoardList.Count - 1);
                                                        if (InBoardList.Count > 0)
                                                            SItem.ScrewDimThroughHBList = InBoardList;
                                                    }
                                                    SItem.Dim = CTempFList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.Dim).Select(item => item.XLength).First();
                                                    SItem.TD = (int)CTempFList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD).Select(item => item.XLength).First();
                                                    //托位深度
                                                    double TH = CTempFList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD).Select(item => item.YLength).Distinct().Max();
                                                    SItem.TH = Convert.ToDecimal(TH);
                                                    SItem.TVCPX = CTempFList[k].CenterPoint.CustomerPoint.X;
                                                    SItem.MatchScrewHole = CTempFList[k].MatchScrewHole;
                                                    SItem.RelScrewHoleList = CTempFList[k].RelScrewHoleList;
                                                    SItem.ItemNum = SItem.RelScrewHoleList.Count;
                                                    RefHoleCenterSplitInfo SInfo = TranRefCHoleData(SItem.ItemNameType, SItem.RelScrewHoleList);
                                                    SItem.HSplitInfo = SInfo;
                                                    SItem.ItemCode = "SpaceBlockScrew";
                                                    CU.ScrewTransToProcessData(SItem);
                                                    List<BoardSectionItem> DTBList = SItem.ScrewDimThroughHBList;
                                                    if (DTBList.Count > 0)
                                                    {
                                                        Boolean DTBF = DTBList.Select(item => item.BoardCode.Equals("fangtie")).ToList().Count > 0;
                                                        if (DTBF)
                                                            ShareItemData.ItemList.Add(SItem);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                                //没有尖
                                if (!CTempFList[k].ToochInfo.ExistTheTip)
                                {
                                    SingleItem SItem = new SingleItem();
                                    SItem.ItemNameType = DItemNameType.SpaceBlockScrew;
                                    double PLMaxY = CTempFList[k].InfoList.Select(item => item.LLine).Max(item => item.StartPoint.CustomerPoint.Y);
                                    double PRMaxY = CTempFList[k].InfoList.Select(item => item.RLine).Max(item => item.StartPoint.CustomerPoint.Y);
                                    double PMaxY = PLMaxY > PRMaxY ? PLMaxY : PRMaxY;
                                    double PLMinY = CTempFList[k].InfoList.Select(item => item.LLine).Min(item => item.EndPoint.CustomerPoint.Y);
                                    double PRMinY = CTempFList[k].InfoList.Select(item => item.RLine).Min(item => item.EndPoint.CustomerPoint.Y);
                                    double PMinY = PLMinY < PRMinY ? PLMinY : PRMinY;
                                    SItem.PeakY = PMaxY;
                                    SItem.NadirY = PMinY;
                                    SItem.RealScrewH = Math.Round(PMaxY - PMinY, 1);
                                    List<BoardSectionItem> NofpepBoardList = new List<BoardSectionItem>(AssemblyShareData.ASectionList);
                                    NofpepBoardList = NofpepBoardList.FindAll(item => !item.BoardCode.Equals("fpBoard") && !item.BoardCode.Equals("epBoard"));
                                    int RBeginIndex = NofpepBoardList.FindLastIndex(item => item.OverheadLine.StartPoint.CustomerPoint.Y >= PMaxY);
                                    int REndIndex = NofpepBoardList.FindIndex(item => item.BottomLine.EndPoint.CustomerPoint.Y <= PMinY);
                                    //方铁螺丝所在的区域
                                    List<BoardSectionItem> InBoardList = NofpepBoardList.GetRange(RBeginIndex, REndIndex - RBeginIndex + 1);
                                    double ThroughPlateH = 0;
                                    if (InBoardList.Count > 0)
                                    {
                                        if (Math.Round(InBoardList[0].OverheadLine.StartPoint.CustomerPoint.Y, 0) > Math.Round(PMaxY, 0))
                                        {
                                            SItem.BlindHoleBoard = InBoardList[0];
                                            gpBoardEndIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardUID.Equals(SItem.BlindHoleBoard.BoardUID));
                                            InBoardList.RemoveAt(0);

                                            if(InBoardList.Count > 0)
                                            {
                                                List<BoardSectionItem> tempBList = new List<BoardSectionItem>();
                                                List <BoardSectionItem> tempFBList = InBoardList.FindAll(item => item.BoardCode.Equals("fangtie")).ToList();
                                                List<BoardSectionItem> tempNFBList = InBoardList.FindAll(item => !item.BoardCode.Equals("fangtie")).ToList();
                                                if(tempFBList.Count > 0)
                                                    tempBList.Add(tempFBList.First());
                                                if(tempNFBList.Count > 0)
                                                    tempBList.AddRange(tempNFBList);
                                                ThroughPlateH = tempBList.Sum(item => item.PlateThick);
                                            }

                                            if (InBoardList.Count > 0)
                                            {
                                                SItem.TDBoard = InBoardList[InBoardList.Count - 1];
                                                InBoardList.RemoveAt(InBoardList.Count - 1);
                                                if (InBoardList.Count > 0)
                                                    SItem.ScrewDimThroughHBList = InBoardList;
                                            }
                                        }
                                    }
                                    double MoreThanBoardH = 0.0;
                                    if (PDim < 20)
                                        MoreThanBoardH = 5;
                                    else
                                        MoreThanBoardH = 10;
                                    SItem.TheoryScrewH = ComputedUtils.RepScrewItemLRule(ThroughPlateH + MoreThanBoardH);
                                    SItem.Dim = CTempFList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.Dim).Select(item => item.XLength).First();
                                    SItem.TD = (int)CTempFList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD).Select(item => item.XLength).First();
                                    //托位深度
                                    double TH = CTempFList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD).Select(item => item.YLength).Distinct().Max();
                                    SItem.TDPosType = InBoardPosType.BoardDown;
                                    SItem.TH = Convert.ToDecimal(TH);
                                    SItem.TVCPX = CTempFList[k].CenterPoint.CustomerPoint.X;
                                    SItem.MatchScrewHole = CTempFList[k].MatchScrewHole;
                                    SItem.RelScrewHoleList = CTempFList[k].RelScrewHoleList;
                                    SItem.ItemNum = SItem.RelScrewHoleList.Count;
                                    RefHoleCenterSplitInfo SInfo = TranRefCHoleData(SItem.ItemNameType, SItem.RelScrewHoleList);
                                    SItem.HSplitInfo = SInfo;
                                    SItem.ItemCode = "SpaceBlockScrew";
                                    CU.ScrewTransToProcessData(SItem);
                                    List<BoardSectionItem> DTBList = SItem.ScrewDimThroughHBList;
                                    if(DTBList.Count > 0)
                                    {
                                        Boolean DTBF = DTBList.Select(item => item.BoardCode.Equals("fangtie")).ToList().Count > 0;
                                        if(DTBF)
                                            ShareItemData.ItemList.Add(SItem);
                                    }
                                }
                            }
                        }

                    }
                }
            }
            catch (Exception ex)
            {
            }
            return gpBoardEndIndex;
        }

        //获取方铁中心线X
        public static double? GetFangtieScrewCLX(List<MixedCAD_Line> ACenterLineList)
        {
            double? ResX = null;
            List<MixedCAD_Line> FTwoSidesACList = ACenterLineList.FindAll(item => item.StartPoint.CustomerPoint.X < FangtieShareData.FLXInfo.SplitX
            || item.StartPoint.CustomerPoint.X > FangtieShareData.FRXInfo.SplitX);
            int fangtieIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("fangtie"));
            BoardSectionItem FBoarditem = AssemblyShareData.ASectionList[fangtieIndex];
            double MaxY = FBoarditem.OverheadLine.StartPoint.CustomerPoint.Y;
            double MinY = FBoarditem.BottomLine.StartPoint.CustomerPoint.Y;
            int AFLIndex = FTwoSidesACList.FindIndex(item => MaxY <= item.StartPoint.CustomerPoint.Y && item.EndPoint.CustomerPoint.Y <= MinY);
            if (AFLIndex != -1)
                ResX = FTwoSidesACList[AFLIndex].StartPoint.CustomerPoint.X;
            return ResX;
        }
        
        //获取回针中心线X
        public static double? GetRPCLX(List<MixedCAD_Line> ACenterLineList)
        {
            double? ResX = null;
            int lastepindex = AssemblyShareData.ASectionList.FindLastIndex(item => item.BoardCode.Equals("epBoard"));
            int fangtieIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("fangtie"));
            if(lastepindex != -1)
            {
                FullInfoLine epFullLine = AssemblyShareData.ASectionList[lastepindex].OverheadLine;
                double MinX = epFullLine.StartPoint.CustomerPoint.X;
                double MaxX = epFullLine.EndPoint.CustomerPoint.X;
                List<MixedCAD_Line> FTwoSidesACList = ACenterLineList.FindAll(item => MinX <= item.StartPoint.CustomerPoint.X && item.EndPoint.CustomerPoint.X <= MaxX);
                double MaxY = AssemblyShareData.ASectionList[fangtieIndex - 1].OverheadLine.StartPoint.CustomerPoint.Y;
                double MinY = AssemblyShareData.ASectionList[lastepindex].OverheadLine.StartPoint.CustomerPoint.Y;
                int AFLIndex = FTwoSidesACList.FindIndex(item => MaxY <= item.StartPoint.CustomerPoint.Y && MinY <= item.EndPoint.CustomerPoint.Y);
            if (AFLIndex != -1)
                ResX = FTwoSidesACList[AFLIndex].StartPoint.CustomerPoint.X;
            }
            return ResX;
        }

        //获取针板螺丝中心线X
        public static double? GetEPFPScrewCLX(List<MixedCAD_Line> ACenterLineList)
        {
            double? ResX = null;
            List<BoardSectionItem> epfpList = AssemblyShareData.ASectionList.FindAll(item => item.BoardCode.Equals("epBoard") 
            || item.BoardCode.Equals("fpBoard"));
            if(epfpList.Count > 0)
            {
                double MaxX = epfpList.Select(item => item.OverheadLine.StartPoint.CustomerPoint.X).ToList().Max();
                double MinX = epfpList.Select(item => item.OverheadLine.EndPoint.CustomerPoint.X).ToList().Min();
                double MaxY = epfpList.Select(item => item.OverheadLine.StartPoint.CustomerPoint.Y).Distinct().ToList().Max();
                double MinY = epfpList.Select(item => item.BottomLine.StartPoint.CustomerPoint.Y).Distinct().ToList().Min();
                //大致范围
                MaxY += 8;
                int epfpLIndex = ACenterLineList.FindIndex(item => item.EndPoint.CustomerPoint.Y <= MinY && item.StartPoint.CustomerPoint.Y <= MaxY);
                if (epfpLIndex != -1)
                    ResX = ACenterLineList[epfpLIndex].StartPoint.CustomerPoint.X;
            }
            return ResX;
        }

        //识别工字螺丝(和方铁螺丝同种规格)  工字螺丝的牙的板作为简化型导柱结束识别的板  TO EDIT
        public static int RecognizeFGenericScrew(Dictionary<double, List<MixedCAD_Line>> AVLineYDic, Dictionary<double, List<MixedCAD_Line>> OBLineYDic)
        {
            int gpBoardEndIndex = -1;
            try
            {
                //标准花式的配板数据
                string FancySelect = (string)dataForm.FancySelectBox.SelectedItem;
                List<StandardCategoryBoard> FancyPlateList = ParamsConfigData.FancyPlateList;
                List<StandardCategoryBoard> StandBoardList = FancyPlateList.FindAll(item => item.category.Equals(FancySelect)).OrderBy(item => item.sortNum).ToList();
                //比对找出当前合适的板
                int bBoardIndex = StandBoardList.FindIndex(item => item.boardCode.Equals("bBoard"));
                int fangtieBoardIndex = StandBoardList.FindIndex(item => item.boardCode.Equals("fangtie"));
                int PerbBoardIndex = bBoardIndex - 1;
                int PerFangtieIndex = fangtieBoardIndex - 1;
                if (PerbBoardIndex > 0 && PerFangtieIndex > 0)
                {
                    string SBcode = StandBoardList[PerbBoardIndex].boardCode;
                    string SBFcode = StandBoardList[PerFangtieIndex].boardCode;
                    BoardSectionItem PerbBoard = AssemblyShareData.ASectionList.Find(item => item.BoardCode.Equals(SBcode));
                    BoardSectionItem PerfangtieBoard = AssemblyShareData.ASectionList.Find(item => item.BoardCode.Equals(SBFcode));
                    if (PerbBoard != null && PerfangtieBoard != null)
                    {
                        //公制螺丝零件集合
                        List<CSingleItem> CTempFList = new List<CSingleItem>();
                        //组装图上 公制螺丝各部位竖线集合
                        List<CSinglePartItem> GItemVList = new List<CSinglePartItem>();

                        //工字螺丝的图元特征收集区域
                        double GMaxY = PerbBoard.BottomLine.UseStartPoint.Y;
                        //牙的范围
                        double GToochMinY = PerfangtieBoard.BottomLine.UseStartPoint.Y;
                        double GMinY = AssemblyShareData.ASectionList[AssemblyShareData.ASectionList.Count - 1].BottomLine.UseStartPoint.Y;

                        List<MixedCAD_Line> PerGVLines = new List<MixedCAD_Line>();
                        List<MixedCAD_Line> GToochOBLine = new List<MixedCAD_Line>();

                        List<double> GVLineKeys = AVLineYDic.Keys.ToList().FindAll(item => GMinY <= Math.Round(item, 0) && Math.Round(item, 0) <= GMaxY);
                        List<double> GOBLineKeys = OBLineYDic.Keys.ToList().FindAll(item => GToochMinY <= Math.Round(item, 0) && Math.Round(item, 0) <= GMaxY);

                        if (GVLineKeys != null)
                            GVLineKeys.ForEach(key => PerGVLines.AddRange(AVLineYDic[key]));

                        if (GOBLineKeys != null)
                            GOBLineKeys.ForEach(key => GToochOBLine.AddRange(OBLineYDic[key]));

                        if (PerGVLines.Count > 0)
                        {
                            List<ScrewHole> FList = HoleCandidateShareData.BigScrewCList;
                            ComputedUtils.SwitchTVHoleCoorType(FList);
                            //识别一组竖线符合 公制螺丝直径         
                            for (int i = 0; i < PerGVLines.Count - 1; i++)
                            {
                                for (int j = 1; j < PerGVLines.Count; j++)
                                {
                                    if (j > i)
                                    {
                                        for (int k = 0; k < FList.Count; k++)
                                        {
                                            double TempDim = Math.Round(Math.Abs(PerGVLines[i].StartPoint.UsePoint.X - PerGVLines[j].StartPoint.UsePoint.X), 2);
                                            // 近似中心对称 计算误差在 + -0.2
                                            double TwoLineSplitAgvCX = Math.Round((PerGVLines[i].StartPoint.UsePoint.X + PerGVLines[j].StartPoint.UsePoint.X) / 2, 1);
                                            double TargetCenterX = Math.Round(FList[k].UseCenterPoint.X, 1);
                                            if (TargetCenterX - 0.2 <= TwoLineSplitAgvCX && TwoLineSplitAgvCX <= TargetCenterX + 0.2)
                                            {
                                                //大致归为公制螺丝部位
                                                CSinglePartItem PItem = new CSinglePartItem();
                                                if (FList[k].Dim - 0.02 <= TempDim && TempDim <= FList[k].Dim + 0.02)
                                                {
                                                    PItem.ItemType = ItemPartCodeType.Dim;
                                                    PItem.LLine = PerGVLines[i];
                                                    PItem.RLine = PerGVLines[j];
                                                    PItem.XLength = TempDim;
                                                    PItem.YLength = Math.Round(Math.Abs(PerGVLines[i].StartPoint.UsePoint.Y - PerGVLines[i].EndPoint.UsePoint.Y), 0);
                                                    PItem.TVCPX = TargetCenterX;
                                                    PItem.MatchScrewHole = FList[k];
                                                    GItemVList.Add(PItem);
                                                }
                                                if (FList[k].TD - 1 <= TempDim && TempDim <= FList[k].TD + 1)
                                                {
                                                    PItem.ItemType = ItemPartCodeType.TD;
                                                    PItem.LLine = PerGVLines[i];
                                                    PItem.RLine = PerGVLines[j];
                                                    PItem.XLength = TempDim;
                                                    PItem.YLength = Math.Round(Math.Abs(PerGVLines[i].StartPoint.UsePoint.Y - PerGVLines[i].EndPoint.UsePoint.Y), 0);
                                                    PItem.TVCPX = TargetCenterX;
                                                    PItem.MatchScrewHole = FList[k];
                                                    GItemVList.Add(PItem);
                                                }
                                            }
                                        }

                                    }
                                }
                            }
                            //去重
                            if (GItemVList.Count > 0)
                            {
                                List<CSinglePartItem> resList = new List<CSinglePartItem>();
                                resList.Add(GItemVList[0]);
                                if (GItemVList.Count > 1)
                                {
                                    for (int i = 1; i < GItemVList.Count; i++)
                                    {
                                        Boolean NoSameFlag = resList.FindIndex(item => CU.JudgeEqualItemPart(item, GItemVList[i])) == -1;
                                        if (NoSameFlag)
                                            resList.Add(GItemVList[i]);
                                    }
                                }
                                GItemVList = resList;
                            }
                            //合并公制螺丝
                            if (GItemVList.Count > 0)
                            {
                                var GroupByList = GItemVList.GroupBy(item => item.TVCPX);
                                foreach (var Item in GroupByList)
                                {
                                    List<CSinglePartItem> ItemPartList = Item.ToList();
                                    CSingleItem CItem = new CSingleItem();
                                    CItem.CenterPoint.CustomerPoint.X = Item.Key;
                                    for (int i = 0; i < ItemPartList.Count; i++)
                                    {
                                        CItem.MatchScrewHole = ItemPartList[i].MatchScrewHole;
                                        CItem.InfoList.Add(ItemPartList[i]);
                                    }
                                    CTempFList.Add(CItem);
                                }
                            }

                            CTempFList = CTempFList.FindAll(item => item.InfoList.Select(info => info.ItemType).Distinct().ToList().Count > 1);
                            //能识别出符合公制螺丝
                            if (CTempFList.Count > 0)
                            {
                                List<BoardSectionItem> NoFallerBoardList = new List<BoardSectionItem>(AssemblyShareData.ASectionList);
                                for (int i = 0; i < CTempFList.Count; i++)
                                    CTempFList[i].RelScrewHoleList = FList.FindAll(item =>
                                       (CTempFList[i].MatchScrewHole.Dim - 0.01 <= item.Dim && item.Dim <= CTempFList[i].MatchScrewHole.Dim + 0.01)
                                       &&
                                       (CTempFList[i].MatchScrewHole.TD - 0.01 <= item.TD && item.TD <= CTempFList[i].MatchScrewHole.TD + 0.01));

                                for (int k = 0; k < CTempFList.Count; k++)
                                {
                                    List<CSinglePartItem> DimPartItemList = CTempFList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.Dim).ToList();
                                    //大约直径
                                    double? PDim = null;
                                    double? DimCenterX = null;
                                    if (DimPartItemList.Count > 0)
                                    {
                                        PDim = DimPartItemList.Select(item => item.XLength).Distinct().First();
                                        DimCenterX = DimPartItemList.Select(item => item.TVCPX).Distinct().First();
                                    }

                                    if (DimCenterX != null)
                                    {
                                        //识别公制螺丝 尖
                                        for (int i = 0; i < GToochOBLine.Count - 1; i++)
                                        {
                                            for (int j = 1; j < GToochOBLine.Count; j++)
                                            {
                                                if (j > i)
                                                {
                                                    double? ToothX = JudgeTwoObliqueTooth(GToochOBLine[i], GToochOBLine[j]);
                                                    Boolean InCenterLineFlag = false;
                                                    if (ToothX != null)
                                                    {
                                                        Boolean F1 = (double)ToothX - 1 <= DimCenterX;
                                                        Boolean F2 = DimCenterX <= (double)ToothX + 1;
                                                        InCenterLineFlag = F1 && F2;
                                                    }
                                                    if (InCenterLineFlag && ToothX != null)
                                                    {
                                                        //客户来图牙深
                                                        double ToochY = 0;
                                                        //穿过的板厚
                                                        double ThroughPlateH = 0;
                                                        //客户来图能找到牙
                                                        CTempFList[k].ToochInfo.ExistTheTip = true;
                                                        double SY = GToochOBLine[i].StartPoint.CustomerPoint.Y;
                                                        double EY = GToochOBLine[i].EndPoint.CustomerPoint.Y;
                                                        //完整牙Y坐标
                                                        double ToochCompY = SY > EY ? SY : EY;
                                                        var StandradTooch = ParamsConfigData.StandardScrewList.Find(item => item.Dimension - 0.02 <= PDim
                                                        && PDim <= item.Dimension + 0.02)?.ScrewDepth;

                                                        List<BoardSectionItem> NofpepBoardList = new List<BoardSectionItem>(AssemblyShareData.ASectionList);
                                                        //找到所在的第一块板
                                                        int GTInBoardIndex = NofpepBoardList.FindIndex(item => item.BottomLine.StartPoint.CustomerPoint.Y < ToochCompY);
                                                        //公制螺丝所在的区域
                                                        List<BoardSectionItem> InBoardList = new List<BoardSectionItem>();
                                                        BoardSectionItem PBNbItem = new BoardSectionItem();
                                                        if (GTInBoardIndex != -1)
                                                        {
                                                            InBoardList = NofpepBoardList.GetRange(GTInBoardIndex, NofpepBoardList.Count - GTInBoardIndex);
                                                            if (InBoardList.Count > 0)
                                                            {
                                                                //有钻头 默认去掉第一块板
                                                                PBNbItem = InBoardList[0];
                                                                InBoardList.RemoveAt(0);
                                                                if (InBoardList.Count > 0)
                                                                {
                                                                    ThroughPlateH = InBoardList.Sum(item => item.PlateThick);
                                                                    ToochY = Math.Round(ToochCompY - InBoardList[InBoardList.Count - 1].BottomLine.EndPoint.CustomerPoint.Y, 0) - ThroughPlateH;
                                                                }
                                                            }
                                                        }

                                                        //量出来的牙深比标准深，取标准值  if牙深比标准浅 取客图尺寸
                                                        if (StandradTooch != null)
                                                            if (Convert.ToDecimal(ToochY) > StandradTooch)
                                                                ToochY = (double)StandradTooch;

                                                        double MoreThanBoardH = 0.0;
                                                        if (PDim < 20)
                                                            MoreThanBoardH = 5;
                                                        else
                                                            MoreThanBoardH = 10;

                                                        SingleItem SItem = new SingleItem();
                                                        SItem.ItemNameType = DItemNameType.GenericScrew;
                                                        List<CSinglePartItem> FRefDimList = CTempFList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.Dim);
                                                        if (FRefDimList.Count > 0)
                                                        {
                                                            double PLMaxY = FRefDimList.Select(item => item.LLine).Max(item => item.StartPoint.CustomerPoint.Y);
                                                            double PRMaxY = FRefDimList.Select(item => item.RLine).Max(item => item.StartPoint.CustomerPoint.Y);
                                                            double PLMinY = FRefDimList.Select(item => item.LLine).Min(item => item.EndPoint.CustomerPoint.Y);
                                                            double PRMinY = FRefDimList.Select(item => item.RLine).Min(item => item.EndPoint.CustomerPoint.Y);
                                                            double PMaxY = PLMaxY > PRMaxY ? PLMaxY : PRMaxY;
                                                            double PMinY = PLMinY < PRMinY ? PLMinY : PRMinY;
                                                            SItem.RealScrewH = Math.Round(PMaxY - PMinY, 0);
                                                        }
                                                        SItem.ToochInfo.ExistTheTip = true;
                                                        SItem.ToochInfo.BlindToochH = ToochY;
                                                        SItem.TheoryScrewH = ComputedUtils.RepScrewItemLRule(ThroughPlateH + MoreThanBoardH);
                                                        SItem.BlindHoleBoard = PBNbItem;
                                                        gpBoardEndIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardUID.Equals(SItem.BlindHoleBoard.BoardUID));
                                                        SItem.TDPosType = InBoardPosType.BoardDown;
                                                        if (InBoardList.Count > 0)
                                                        {
                                                            SItem.TDBoard = InBoardList[InBoardList.Count - 1];
                                                            InBoardList.RemoveAt(InBoardList.Count - 1);
                                                            if (InBoardList.Count > 0)
                                                                SItem.ScrewDimThroughHBList = InBoardList;
                                                        }
                                                        SItem.Dim = CTempFList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.Dim).Select(item => item.XLength).First();
                                                        SItem.TD = (int)CTempFList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD).Select(item => item.XLength).First();
                                                        double TH = CTempFList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD).Select(item => item.YLength).Distinct().Max();
                                                        SItem.TH = Convert.ToDecimal(TH);
                                                        SItem.TVCPX = CTempFList[k].CenterPoint.CustomerPoint.X;
                                                        SItem.MatchScrewHole = CTempFList[k].MatchScrewHole;
                                                        SItem.RelScrewHoleList = CTempFList[k].RelScrewHoleList;
                                                        SItem.ItemNum = SItem.RelScrewHoleList.Count;
                                                        RefHoleCenterSplitInfo SInfo = TranRefCHoleData(SItem.ItemNameType, SItem.RelScrewHoleList);
                                                        SItem.HSplitInfo = SInfo;
                                                        SItem.ItemCode = "GenericScrew";
                                                        ShareItemData.ItemList.Add(SItem);
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    if (!CTempFList[k].ToochInfo.ExistTheTip)
                                    {
                                        SingleItem SItem = new SingleItem();
                                        SItem.ItemNameType = DItemNameType.SpaceBlockScrew;
                                        double PLMaxY = CTempFList[k].InfoList.Select(item => item.LLine).Max(item => item.StartPoint.CustomerPoint.Y);
                                        double PRMaxY = CTempFList[k].InfoList.Select(item => item.RLine).Max(item => item.StartPoint.CustomerPoint.Y);
                                        double PMaxY = PLMaxY > PRMaxY ? PLMaxY : PRMaxY;
                                        double PLMinY = CTempFList[k].InfoList.Select(item => item.LLine).Min(item => item.EndPoint.CustomerPoint.Y);
                                        double PRMinY = CTempFList[k].InfoList.Select(item => item.RLine).Min(item => item.EndPoint.CustomerPoint.Y);
                                        double PMinY = PLMinY < PRMinY ? PLMinY : PRMinY;
                                        SItem.RealScrewH = Math.Round(PMaxY - PMinY, 1);
                                        List<BoardSectionItem> NofpepBoardList = new List<BoardSectionItem>(AssemblyShareData.ASectionList);
                                        int RBeginIndex = NofpepBoardList.FindLastIndex(item => item.OverheadLine.StartPoint.CustomerPoint.Y >= PMaxY);
                                        int REndIndex = NofpepBoardList.FindIndex(item => item.BottomLine.EndPoint.CustomerPoint.Y <= PMinY);
                                        //公制螺丝所在的区域
                                        List<BoardSectionItem> InBoardList = NofpepBoardList.GetRange(RBeginIndex, REndIndex - RBeginIndex + 1);
                                        double ThroughPlateH = 0;
                                        if (InBoardList.Count > 0)
                                        {
                                            if (Math.Round(InBoardList[0].OverheadLine.StartPoint.CustomerPoint.Y, 0) > Math.Round(PMaxY, 0))
                                            {
                                                SItem.BlindHoleBoard = InBoardList[0];
                                                gpBoardEndIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardUID.Equals(SItem.BlindHoleBoard.BoardUID));
                                                InBoardList.RemoveAt(0);
                                                ThroughPlateH = InBoardList.Sum(item => item.PlateThick);
                                                if (InBoardList.Count > 0)
                                                {
                                                    SItem.TDBoard = InBoardList[InBoardList.Count - 1];
                                                    InBoardList.RemoveAt(InBoardList.Count - 1);
                                                    if (InBoardList.Count > 0)
                                                        SItem.ScrewDimThroughHBList = InBoardList;
                                                }
                                            }
                                        }
                                        double MoreThanBoardH = 0.0;
                                        if (PDim < 20)
                                            MoreThanBoardH = 5;
                                        else
                                            MoreThanBoardH = 10;
                                        SItem.TheoryScrewH = ComputedUtils.RepScrewItemLRule(ThroughPlateH + MoreThanBoardH);
                                        SItem.Dim = CTempFList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.Dim).Select(item => item.XLength).First();
                                        SItem.TD = (int)CTempFList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD).Select(item => item.XLength).First();
                                        double TH = CTempFList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD).Select(item => item.YLength).Distinct().Max();
                                        SItem.TDPosType = InBoardPosType.BoardDown;
                                        SItem.TH = Convert.ToDecimal(TH);
                                        SItem.TVCPX = CTempFList[k].CenterPoint.CustomerPoint.X;
                                        SItem.MatchScrewHole = CTempFList[k].MatchScrewHole;
                                        SItem.RelScrewHoleList = CTempFList[k].RelScrewHoleList;
                                        SItem.ItemNum = SItem.RelScrewHoleList.Count;
                                        RefHoleCenterSplitInfo SInfo = TranRefCHoleData(SItem.ItemNameType, SItem.RelScrewHoleList);
                                        SItem.HSplitInfo = SInfo;
                                        SItem.ItemCode = "GenericScrew";
                                        ShareItemData.ItemList.Add(SItem);
                                    }
                                }
                            }

                        }

                    }
                }
            }
            catch (Exception)
            {
            }
            return gpBoardEndIndex;
        }

        public static void RecognizeBottomRPItem(string Strategy, Dictionary<double, List<MixedCAD_Line>> AVLineYDic, 
            Dictionary<double, List<MixedCAD_Line>> OBLineYDic,
            List<MixedCAD_Curve> AVCurveList, List<MixedCAD_Line> ACenterLineList)
        {
            try
            {
                List<CSingleItem> CTempPRList = new List<CSingleItem>();
                List<CSinglePartItem> RPItemVList = new List<CSinglePartItem>();
                int stBoardIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("stBoard"));
                int AutoaBoardIndex = AssemblyShareData.ASectionList.FindLastIndex(item => item.BoardCode.Equals("aBoard"));
                int BeginIndex = -1;
                if (stBoardIndex != -1)
                    BeginIndex = stBoardIndex;
                else
                   if (AutoaBoardIndex != -1)
                    BeginIndex = AutoaBoardIndex;
                //Determine Recognize Position scope
                BoardSectionItem fpBoardInfo = AssemblyShareData.ASectionList.FindLast(item => item.BoardCode.Equals("fpBoard"));
                
                int lastepBIndex = AssemblyShareData.ASectionList.FindLastIndex(item => item.BoardCode.Equals("epBoard"));
                if(lastepBIndex == -1)
                    lastepBIndex = AssemblyShareData.ASectionList.FindLastIndex(item => item.BoardCode.Equals("fpBoard"));

                if (BeginIndex != -1 && fpBoardInfo != null)
                {
                    List<MixedCAD_Line> RPVLines = new List<MixedCAD_Line>();
                    BoardSectionItem BeginBoardInfo = AssemblyShareData.ASectionList[BeginIndex];
                    BoardSectionItem EndBoardInfo = AssemblyShareData.ASectionList[lastepBIndex];
                    //lastepBIndex
                    //Scene: Customer DWG maybe Draw RP Off-Air position Diff Scope
                    double MaxY = Math.Round(BeginBoardInfo.OverheadLine.UseStartPoint.Y, 0);
                    double MinY = Math.Round(EndBoardInfo.BottomLine.UseStartPoint.Y, 0);
                    MaxY += 20;
                    MinY -= 5;
                    double ERRORLX = Math.Round(fpBoardInfo.BottomLine.UseStartPoint.X, 0);
                    double ERRORRX = Math.Round(fpBoardInfo.BottomLine.UseEndPoint.X, 0);
                    List<double> rpBoardVLineKeys = AVLineYDic.Keys.ToList().FindAll(item => MinY <= Math.Round(item,0) && Math.Round(item, 0) <= MaxY);
                    if (rpBoardVLineKeys != null)
                        rpBoardVLineKeys.ForEach(key => RPVLines.AddRange(AVLineYDic[key]));
                    RPVLines = RPVLines.FindAll(item => Math.Round(item.StartPoint.UsePoint.Y, 0) <= MaxY);
                    RPVLines = RPVLines.FindAll(item => ERRORLX <= item.StartPoint.UsePoint.X && item.StartPoint.UsePoint.X <= ERRORRX);
                    List<ScrewHole> TVRPHoleList = HoleCandidateShareData.ReturnPinCList;
                    if (TVRPHoleList.Count > 0)
                    {
                        List<double> CRPX = TVRPHoleList.Select(item => item.CenterPoint.TransSplitPoint.X).Distinct().ToList();
                        double refDim = TVRPHoleList[0].Dim;
                        double refTD = TVRPHoleList[0].TD;
                        if (RPVLines.Count > 0 && CRPX.Count > 0)
                        {
                            if (Strategy.Equals("PLANA"))
                            {
                                for (int i = 0; i < RPVLines.Count - 1; i++)
                                {
                                    for (int j = 1; j < RPVLines.Count; j++)
                                    {
                                        if (j > i)
                                        {
                                            for (int k = 0; k < CRPX.Count; k++)
                                            {
                                                double TempDim = Math.Round(Math.Abs(RPVLines[i].StartPoint.UsePoint.X - RPVLines[j].StartPoint.UsePoint.X), 2);
                                                //Approximate Centrosymmetry Error +- 0.2
                                                double TwoLineSplitAgvCX = Math.Round((RPVLines[i].StartPoint.UsePoint.X + RPVLines[j].StartPoint.UsePoint.X) / 2, 1);
                                                double TwoLineCustomerAgvCX = Math.Round((RPVLines[i].StartPoint.CustomerPoint.X + RPVLines[j].StartPoint.CustomerPoint.X) / 2, 1);
                                                double TargetCenterX = Math.Round(CRPX[k], 1);
                                                double LX = TargetCenterX - 5;
                                                double RX = TargetCenterX + 5;
                                                if (LX <= TwoLineSplitAgvCX && TwoLineSplitAgvCX <= RX)
                                                {
                                                    CSinglePartItem RPItem = new CSinglePartItem();
                                                    if (refDim - 0.02 <= TempDim && TempDim <= refDim + 0.02)
                                                    {
                                                        RPItem.ItemType = ItemPartCodeType.Dim;
                                                        RPItem.LLine = RPVLines[i];
                                                        RPItem.RLine = RPVLines[j];
                                                        RPItem.XLength = TempDim;
                                                        RPItem.YLength = Math.Round(Math.Abs(RPVLines[i].StartPoint.CustomerPoint.Y - RPVLines[i].EndPoint.CustomerPoint.Y), 0);
                                                        RPItem.AVCustomerCX = TwoLineCustomerAgvCX;
                                                        RPItem.AVSplitCX = TwoLineSplitAgvCX;
                                                        RPItem.TVCPX = TargetCenterX;
                                                        RPItemVList.Add(RPItem);
                                                    }
                                                    if (refTD - 1 <= TempDim && TempDim <= refTD + 1)
                                                    {
                                                        RPItem.ItemType = ItemPartCodeType.TD;
                                                        RPItem.LLine = RPVLines[i];
                                                        RPItem.RLine = RPVLines[j];
                                                        RPItem.XLength = TempDim;
                                                        RPItem.YLength = Math.Round(Math.Abs(RPVLines[i].StartPoint.CustomerPoint.Y - RPVLines[i].EndPoint.CustomerPoint.Y), 0);
                                                        RPItem.AVCustomerCX = TwoLineCustomerAgvCX;
                                                        RPItem.AVSplitCX = TwoLineSplitAgvCX;
                                                        RPItem.TVCPX = TargetCenterX;
                                                        RPItemVList.Add(RPItem);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                if (RPItemVList.Count > 0)
                                {
                                    for (int i = 0; i < RPItemVList.Count; i++)
                                    {
                                        double refX = RPItemVList[i].TVCPX;
                                        int tIndex = TVRPHoleList.FindIndex(item => Math.Round(item.CenterPoint.TransSplitPoint.X, 1) == refX);
                                        if (tIndex != -1)
                                            RPItemVList[i].MatchScrewHole = TVRPHoleList[tIndex];
                                    }
                                }
                            }

                            if (Strategy.Equals("PLANB"))
                            {
                                double? RPCLX = GetRPCLX(ACenterLineList);
                                ScrewHole refHoleItem = TVRPHoleList[0];
                                if (RPCLX != null)
                                {
                                    //RP Center Line +- 5
                                    double TargetCenterX = Math.Round((double)RPCLX, 1);
                                    double LX = TargetCenterX - 5;
                                    double RX = TargetCenterX + 5;
                                    for (int i = 0; i < RPVLines.Count - 1; i++)
                                    {
                                        for (int j = 1; j < RPVLines.Count; j++)
                                        {
                                            if (j > i)
                                            {
                                                double TempDim = Math.Round(Math.Abs(RPVLines[i].StartPoint.UsePoint.X - RPVLines[j].StartPoint.UsePoint.X), 2);
                                                double TwoLineSplitAgvCX = Math.Round((RPVLines[i].StartPoint.UsePoint.X + RPVLines[j].StartPoint.UsePoint.X) / 2, 1);
                                                double TwoLineCustomerAgvCX = Math.Round((RPVLines[i].StartPoint.CustomerPoint.X + RPVLines[j].StartPoint.CustomerPoint.X) / 2, 1);
                                                if (LX <= TwoLineSplitAgvCX && TwoLineSplitAgvCX <= RX)
                                                {
                                                    CSinglePartItem RPItem = new CSinglePartItem();
                                                    if (refHoleItem.Dim - 0.02 <= TempDim && TempDim <= refHoleItem.Dim + 0.02)
                                                    {
                                                        //Dim
                                                        RPItem.ItemType = ItemPartCodeType.Dim;
                                                        RPItem.LLine = RPVLines[i];
                                                        RPItem.RLine = RPVLines[j];
                                                        RPItem.XLength = TempDim;
                                                        RPItem.YLength = Math.Round(Math.Abs(RPVLines[i].StartPoint.CustomerPoint.Y - RPVLines[i].EndPoint.CustomerPoint.Y), 0);
                                                        RPItem.AVCustomerCX = TwoLineCustomerAgvCX;
                                                        RPItem.AVSplitCX = TwoLineSplitAgvCX;
                                                        RPItem.TVCPX = TargetCenterX;
                                                        RPItemVList.Add(RPItem);
                                                    }
                                                    if (refHoleItem.TD - 1 <= TempDim && TempDim <= refHoleItem.TD + 1)
                                                    {
                                                        //TD
                                                        RPItem.ItemType = ItemPartCodeType.TD;
                                                        RPItem.LLine = RPVLines[i];
                                                        RPItem.RLine = RPVLines[j];
                                                        RPItem.XLength = TempDim;
                                                        RPItem.YLength = Math.Round(Math.Abs(RPVLines[i].StartPoint.CustomerPoint.Y - RPVLines[i].EndPoint.CustomerPoint.Y), 0);
                                                        RPItem.AVCustomerCX = TwoLineCustomerAgvCX;
                                                        RPItem.AVSplitCX = TwoLineSplitAgvCX;
                                                        RPItem.TVCPX = TargetCenterX;
                                                        RPItemVList.Add(RPItem);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    if (RPItemVList.Count > 0)
                                    {
                                        for (int i = 0; i < RPItemVList.Count; i++)
                                        {
                                            double refX = RPItemVList[i].TVCPX;
                                            int tIndex = TVRPHoleList.FindIndex(item => Math.Round(item.CenterPoint.TransSplitPoint.X, 1) == refX);
                                            if (tIndex != -1)
                                                RPItemVList[i].MatchScrewHole = TVRPHoleList[tIndex];
                                        }
                                    }
                                }
                            }

                            if (RPItemVList.Count > 0)
                            {
                                List<CSinglePartItem> TDPartList = RPItemVList.FindAll(item => CU.JudgeTwoYLineNoTooOverDis(item.LLine, item.RLine));
                                TDPartList = TDPartList.FindAll(item => item.ItemType == ItemPartCodeType.TD).ToList();
                                if (TDPartList.Count > 0)
                                {
                                    double computedTDX = CU.FindItemAVSplitCX(TDPartList);
                                    RPItemVList = RPItemVList.FindAll(item => item.AVSplitCX == computedTDX).ToList();

                                    //Dup Removal
                                    if (RPItemVList.Count > 0)
                                    {
                                        List<CSinglePartItem> resList = new List<CSinglePartItem>();
                                        resList.Add(RPItemVList[0]);
                                        if (RPItemVList.Count > 1)
                                        {
                                            for (int i = 1; i < RPItemVList.Count; i++)
                                            {
                                                Boolean NoSameFlag = resList.FindIndex(item => CU.JudgeEqualItemPart(item, RPItemVList[i])) == -1;
                                                if (NoSameFlag)
                                                    resList.Add(RPItemVList[i]);
                                            }
                                        }
                                        RPItemVList = resList;
                                    }

                                    //Merge key CenterPoint.CustomerPoint.X (TVCPX)
                                    if (RPItemVList.Count > 0)
                                    {
                                        var GroupByList = RPItemVList.GroupBy(item => item.TVCPX);
                                        foreach (var Item in GroupByList)
                                        {
                                            List<CSinglePartItem> ItemPartList = Item.ToList();
                                            CSingleItem CItem = new CSingleItem();
                                            CItem.CenterPoint.CustomerPoint.X = Item.Key;
                                            for (int i = 0; i < ItemPartList.Count; i++)
                                            {
                                                CItem.MatchScrewHole = ItemPartList[i].MatchScrewHole;
                                                CItem.InfoList.Add(ItemPartList[i]);
                                            }
                                            CTempPRList.Add(CItem);
                                        }
                                    }

                                    CTempPRList = CTempPRList.FindAll(item => item.InfoList.Select(info => info.ItemType).ToList().Count > 1);
                                    if (CTempPRList.Count > 0)
                                    {
                                        //TD Dim Relevance MayBe Error
                                        for (int i = 0; i < CTempPRList.Count; i++)
                                            CTempPRList[i].RelScrewHoleList = TVRPHoleList.FindAll(item =>
                                            (CTempPRList[i].MatchScrewHole.Dim - 0.01 <= item.Dim && item.Dim <= CTempPRList[i].MatchScrewHole.Dim + 0.01)
                                            &&
                                            (CTempPRList[i].MatchScrewHole.TD - 0.01 <= item.TD && item.TD <= CTempPRList[i].MatchScrewHole.TD + 0.01));

                                        //Remove fangtie disturb
                                        List<BoardSectionItem> OriginList = AssemblyShareData.ASectionList.FindAll(item => !item.BoardCode.Equals("fangtie"));

                                        //Find RP Tooch
                                        for (int k = 0; k < CTempPRList.Count; k++)
                                        {
                                            double RPRMaxY = CTempPRList[k].InfoList.Select(item => item.RLine.StartPoint.CustomerPoint.Y).ToList().Max();
                                            double RPLMaxY = CTempPRList[k].InfoList.Select(item => item.LLine.StartPoint.CustomerPoint.Y).ToList().Max();
                                            double RPMaxY = RPRMaxY > RPLMaxY ? RPRMaxY : RPLMaxY;
                                            int toochBIndex = AssemblyShareData.ASectionList.FindLastIndex(item => item.BottomLine.StartPoint.CustomerPoint.Y >= RPMaxY);
                                            List<BoardSectionItem> ToochScopeBList = AssemblyShareData.ASectionList.GetRange(toochBIndex, 2);
                                            double toochScopeMaxY = ToochScopeBList.First().OverheadLine.StartPoint.CustomerPoint.Y;
                                            toochScopeMaxY += 15;
                                            double toochScopeMinY = ToochScopeBList.Last().BottomLine.StartPoint.CustomerPoint.Y;
                                            List<MixedCAD_Line> toochVLines = new List<MixedCAD_Line>();
                                            List<double> RPToochVLineKeys = AVLineYDic.Keys.ToList().FindAll(item => Math.Round(item, 0) <= toochScopeMaxY);
                                            if (RPToochVLineKeys != null)
                                                RPToochVLineKeys.ForEach(key => toochVLines.AddRange(AVLineYDic[key]));
                                            toochVLines = toochVLines.FindAll(item => toochScopeMinY <= item.EndPoint.CustomerPoint.Y && item.StartPoint.CustomerPoint.Y <= toochScopeMaxY).ToList();
                                            //Group Of Tooch Info
                                            List<CSinglePartItem> groupToochPartItemList = new List<CSinglePartItem>();
                                            List<CSinglePartItem> DimPartItemList = CTempPRList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.Dim).ToList();
                                            double ToochCompareDim = 0;
                                            double? toothRefCX = null;
                                            if (DimPartItemList.Count > 0)
                                            {
                                                ToochCompareDim = DimPartItemList.Select(item => item.XLength).Distinct().First();
                                                CSinglePartItem refPartItem = DimPartItemList.First();
                                                toothRefCX = refPartItem.AVSplitCX;
                                            }
                                            if (toothRefCX != null)
                                            {
                                                if (toochVLines.Count > 1)
                                                {
                                                    for(int mi = 0; mi < toochVLines.Count; mi++)
                                                    {
                                                        // int mj = mi + 1;
                                                        int mj = toochVLines.FindIndex(item => JudgeSameXVertical(item, toochVLines[mi]));
                                                        if(mj != -1)
                                                        {
                                                            Boolean noSameF = mi != mj;
                                                            if (noSameF)
                                                            {
                                                                toochVLines[mj] = MergeSameVertical(toochVLines[mi], toochVLines[mj]);
                                                                toochVLines.RemoveAt(mi);
                                                                mi++;
                                                            }
                                                        }
                                                    } 

                                                    double reftX = (double)toothRefCX;
                                                    for (int i = 0; i < toochVLines.Count - 1; i++)
                                                    {
                                                        for (int j = 1; j < toochVLines.Count; j++)
                                                        {
                                                            if (j > i)
                                                            {
                                                                double TLCenterX = Math.Round((toochVLines[i].StartPoint.CustomerPoint.X + toochVLines[j].StartPoint.CustomerPoint.X) / 2, 0);
                                                                if (TLCenterX - 1 <= reftX && reftX <= TLCenterX + 1)
                                                                {
                                                                    CSinglePartItem ToochItem = new CSinglePartItem();
                                                                    double IX = toochVLines[i].StartPoint.CustomerPoint.X;
                                                                    double JX = toochVLines[j].StartPoint.CustomerPoint.X;
                                                                    if (IX < JX)
                                                                    {
                                                                        ToochItem.LLine = toochVLines[i];
                                                                        ToochItem.RLine = toochVLines[j];
                                                                    }
                                                                    else
                                                                    {
                                                                        ToochItem.LLine = toochVLines[j];
                                                                        ToochItem.RLine = toochVLines[i];
                                                                    }
                                                                    double toochX = ToochItem.RLine.StartPoint.CustomerPoint.X - ToochItem.LLine.StartPoint.CustomerPoint.X;
                                                                    if (toochX < ToochCompareDim)
                                                                        groupToochPartItemList.Add(ToochItem);
                                                                }
                                                            }
                                                        }
                                                    }

                                                    groupToochPartItemList = groupToochPartItemList.FindAll(item => ComputedUtils.FilterMisMatchToochDimGroupLine(item.LLine, item.RLine)).ToList();
                                                    int toochfitNum = groupToochPartItemList.Count;
                                                    if (toochfitNum >= 1)
                                                    {
                                                        List<MixedCAD_Line> toochLLineList = groupToochPartItemList.Select(item => item.LLine).ToList();
                                                        List<MixedCAD_Line> toochRLineList = groupToochPartItemList.Select(item => item.RLine).ToList();

                                                        //Find Dim YLine
                                                        double ToochLDimL = toochLLineList.Max(item => item.Length);
                                                        double ToochRDimL = toochRLineList.Max(item => item.Length);

                                                        List<MixedCAD_Line> toochLDimList = toochLLineList.FindAll(item => item.Length == ToochLDimL).ToList();
                                                        List<MixedCAD_Line> toochRDimList = toochRLineList.FindAll(item => item.Length == ToochRDimL).ToList();
                                                        double toochDimRX = toochRDimList.Select(item => item.StartPoint.CustomerPoint.X).Max();
                                                        double toochDimLX = toochLDimList.Select(item => item.StartPoint.CustomerPoint.X).Min();
                                                        double toochDimL = ToochLDimL > ToochRDimL ? ToochLDimL : ToochRDimL;
                                                        MixedCAD_Line toochDimRLine = toochRLineList.Find(item => item.StartPoint.CustomerPoint.X == toochDimRX);
                                                        MixedCAD_Line toochDimLLine = toochLLineList.Find(item => item.StartPoint.CustomerPoint.X == toochDimLX);

                                                        CTempPRList[k].ToochInfo.toochParam.ToochDimPart.RLine = toochDimRLine;
                                                        CTempPRList[k].ToochInfo.toochParam.ToochDimPart.LLine = toochDimLLine;
                                                        double toochDim = Math.Round(Math.Abs(toochDimRX - toochDimLX), 1);
                                                        CTempPRList[k].ToochInfo.toochParam.ToochDimPart.Dim = toochDim;
                                                        //Exist Tooch
                                                        CTempPRList[k].ToochInfo.toochParam.ToochDimPart.HasF = true;
                                                        if (toochfitNum >= 2)
                                                        {
                                                            //Find RP Screw TD YLine
                                                            double MaxToochLY = toochLLineList.Max(item => item.StartPoint.CustomerPoint.Y);
                                                            double MaxToochRY = toochRLineList.Max(item => item.StartPoint.CustomerPoint.Y);
                                                            List<MixedCAD_Line> toochLTDList = toochLLineList.FindAll(item => item.StartPoint.CustomerPoint.Y == MaxToochLY).ToList();
                                                            List<MixedCAD_Line> toochRTDList = toochRLineList.FindAll(item => item.StartPoint.CustomerPoint.Y == MaxToochRY).ToList();
                                                            double toochTDRL = toochLTDList.Select(item => item.Length).Max();
                                                            double toochTDLL = toochRTDList.Select(item => item.Length).Max();
                                                            double toochTDL = toochTDRL > toochTDLL ? toochTDRL : toochTDLL;
                                                            MixedCAD_Line toochTDRLine = toochLTDList.Find(item => item.Length == toochTDRL);
                                                            MixedCAD_Line toochTDLLine = toochRTDList.Find(item => item.Length == toochTDLL);
                                                            double toochTD = Math.Abs(toochTDRLine.StartPoint.CustomerPoint.X - toochTDLLine.StartPoint.CustomerPoint.X);
                                                            //Compare YDiff and XDiff to Judge Diff Part
                                                            Boolean toochF1 = toochDimL != toochTDL;
                                                            Boolean toochF2 = toochDim != toochTD;
                                                            if (toochF1 && toochF2)
                                                            {
                                                                CTempPRList[k].ToochInfo.toochParam.ToochTDPart.RLine = toochTDRLine;
                                                                CTempPRList[k].ToochInfo.toochParam.ToochTDPart.LLine = toochTDLLine;
                                                                CTempPRList[k].ToochInfo.toochParam.ToochTDPart.TD = toochTD;
                                                                CTempPRList[k].ToochInfo.toochParam.ToochTDPart.HasF = true;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                        int aBoardLastIndex = AssemblyShareData.ASectionList.FindLastIndex(item => item.BoardCode.Equals("aBoard"));
                                        double LastaBoardMinY = Math.Round(AssemblyShareData.ASectionList[aBoardLastIndex].BottomLine.StartPoint.CustomerPoint.Y, 0);
                                        for (int i = 0; i < CTempPRList.Count; i++)
                                        {
                                            if (CTempPRList[i].InfoList.Count > 0)
                                            {
                                                Boolean DimF = CTempPRList[i].InfoList.FindIndex(item => item.ItemType == ItemPartCodeType.Dim) != -1;
                                                Boolean TDF = CTempPRList[i].InfoList.FindIndex(item => item.ItemType == ItemPartCodeType.TD) != -1;
                                                if (DimF && TDF)
                                                {
                                                    //Cut Off  Flag
                                                    Boolean HasCutOffF = false;
                                                    SingleItem RPItem = new SingleItem();
                                                    RPItem.ItemNameType = DItemNameType.ReturnPin;
                                                    List<CSinglePartItem> CTempPRDimPartList = CTempPRList[i].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.Dim).ToList();
                                                    double RPLMaxY = CTempPRDimPartList.Select(item => item.LLine).Max(item => item.StartPoint.CustomerPoint.Y);
                                                    double RPRMaxY = CTempPRDimPartList.Select(item => item.RLine).Max(item => item.StartPoint.CustomerPoint.Y);
                                                    double RPMaxY = RPLMaxY > RPRMaxY ? RPLMaxY : RPRMaxY;
                                                    List<CSinglePartItem> CTempPRTDPartList = CTempPRList[i].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD).ToList();
                                                    double RPLMinY = CTempPRTDPartList.Select(item => item.LLine).Min(item => item.EndPoint.CustomerPoint.Y);
                                                    double RPRMinY = CTempPRTDPartList.Select(item => item.RLine).Min(item => item.EndPoint.CustomerPoint.Y);
                                                    double RPMinY = RPLMinY < RPRMinY ? RPLMinY : RPRMinY;
                                                    if (AVCurveList.Count > 0)
                                                    {
                                                        RPCutOffInfo RPCutOffInfo = new RPCutOffInfo();
                                                        if (RPLMaxY > RPRMaxY)
                                                        {
                                                            RPCutOffInfo.traitType = RPPointTraitType.LHight;
                                                            RPCutOffInfo.LPoint.Y = RPMaxY;
                                                        }
                                                        else
                                                        {
                                                            RPCutOffInfo.traitType = RPPointTraitType.RHight;
                                                            RPCutOffInfo.RPoint.Y = RPMaxY;
                                                        }
                                                        double Dim = CTempPRList[i].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.Dim).Select(item => item.XLength).First();
                                                        double curLX = CTempPRList[i].CenterPoint.CustomerPoint.X - Dim / 2;
                                                        double curRX = CTempPRList[i].CenterPoint.CustomerPoint.X + Dim / 2;
                                                        RPCutOffInfo.LPoint.X = curLX;
                                                        RPCutOffInfo.RPoint.X = curRX;
                                                        MixedCAD_Curve RPCur = AVCurveList.Find(item => CU.JudgeCurveInPartArea(RPCutOffInfo, item));
                                                        //Exist Cut Off
                                                        if (RPCur != null)
                                                        {
                                                            HasCutOffF = true;
                                                            //If Has stBoard And No Pass stBoard By Customer DWG Length 
                                                            int cutOffstBoardIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("stBoard"));
                                                            if (cutOffstBoardIndex != -1)
                                                            {
                                                                double tuiOverY = AssemblyShareData.ASectionList[cutOffstBoardIndex].OverheadLine.StartPoint.CustomerPoint.Y;
                                                                if (RPMaxY < tuiOverY)
                                                                    RPItem.TheoryH = RPItem.RealH;
                                                            }
                                                            else
                                                            {
                                                                //TheoryH = bBoard(& Under) ~ Fangtie - epBoard
                                                                int BBoardIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("bBoard"));
                                                                int FangtieBoardIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("fangtie"));
                                                                int epBoardIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("epBoard"));
                                                                List<BoardSectionItem> BuntilFList = AssemblyShareData.ASectionList.GetRange(BBoardIndex, FangtieBoardIndex - BBoardIndex + 1);
                                                                if (BuntilFList.Count > 0)
                                                                {
                                                                    BuntilFList = BuntilFList.FindAll(item => !item.BoardCode.Equals("epBoard") && !item.BoardCode.Equals("fpBoard"));
                                                                    if (BuntilFList.Count > 0)
                                                                    {
                                                                        double CutOffPlateThick = 0;
                                                                        BuntilFList.ForEach(item => CutOffPlateThick += item.PlateThick);
                                                                        CutOffPlateThick -= AssemblyShareData.ASectionList[epBoardIndex].PlateThick;
                                                                        RPItem.TheoryH = CutOffPlateThick;
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }

                                                    int RPBeginIndex = OriginList.FindIndex(item => item.OverheadLine.StartPoint.CustomerPoint.Y <= RPMaxY);
                                                    int RPEndIndex = OriginList.FindIndex(item => item.BottomLine.EndPoint.CustomerPoint.Y <= RPMinY);

                                                    //RP Screw Pass Board Scope 
                                                    List<BoardSectionItem> InBoardList = OriginList.GetRange(RPBeginIndex, RPEndIndex - RPBeginIndex + 1)
                                                        .FindAll(item => !item.BoardCode.Equals("fangtie"));
                                                    List<BoardSectionItem> RAbovefangtieBoardList = InBoardList.FindAll(item => !item.BoardCode.Equals("fpBoard")
                                                    && !item.BoardCode.Equals("epBoard"));

                                                    RPItem.ToochInfo = CTempPRList[i].ToochInfo;
                                                    RPItem.PeakY = RPMaxY;
                                                    RPItem.NadirY = RPMinY;
                                                    RPItem.ItemDimThroughHBList = InBoardList;
                                                    RPItem.RealH = Convert.ToInt32(Math.Round(RPMaxY - RPMinY, 0));
                                                    
                                                    Boolean existToochDimF = RPItem.ToochInfo.toochParam.ToochDimPart.HasF;
                                                    Boolean existToochTDF = RPItem.ToochInfo.toochParam.ToochTDPart.HasF;
                                                    SingleItem RPScrewItem = new SingleItem();
                                                    //Add Tooch Remark
                                                    if (existToochDimF)
                                                    {
                                                        double toochDim = RPItem.ToochInfo.toochParam.ToochDimPart.Dim;
                                                        StandardScrew mayBeSScrew = ParamsConfigData.StandardScrewList.Find(item => 
                                                        Convert.ToDouble(item.Dimension) - 0.2 <= toochDim
                                                        && toochDim <= Convert.ToDouble(item.Dimension) + 0.2);
                                                        if (mayBeSScrew != null)
                                                            RPItem.Remark = "加牙M" + mayBeSScrew.Dimension;
                                                        //if Has TD that mean Exist RP Screw
                                                        if (existToochTDF)
                                                        {
                                                            RPScrewItem.ItemNameType = DItemNameType.ReturnPinScrew;
                                                            RPScrewItem.Dim = RPItem.ToochInfo.toochParam.ToochDimPart.Dim;
                                                            RPScrewItem.ItemCode = "ReturnPinScrew";
                                                            
                                                            //Judge Tooch Scope 判断 客图 Dim线段是否超出'业务'范围
                                                            double rpScrewTDREY = Math.Round(RPItem.ToochInfo.toochParam.ToochTDPart.RLine.EndPoint.CustomerPoint.Y,1);
                                                            double rpScrewTDLEY = Math.Round(RPItem.ToochInfo.toochParam.ToochTDPart.LLine.EndPoint.CustomerPoint.Y,1);
                                                            double REDY = Math.Round(RPItem.ToochInfo.toochParam.ToochDimPart.RLine.EndPoint.CustomerPoint.Y,1);
                                                            double LEDY = Math.Round(RPItem.ToochInfo.toochParam.ToochDimPart.LLine.EndPoint.CustomerPoint.Y,1);
                                                            double rpScrewTDRefEY = rpScrewTDREY > rpScrewTDLEY ? rpScrewTDREY : rpScrewTDLEY;
                                                            double rpScrewDimRefEY = REDY < LEDY ? REDY : LEDY;

                                                            //RPScrew Board
                                                            int rpScrewBeginBIndex = AssemblyShareData.ASectionList.FindLastIndex(item => Math.Round(item.OverheadLine.StartPoint.CustomerPoint.Y, 1)
                                                            >= rpScrewTDRefEY);
                                                            int rpScrewEndBIndex = AssemblyShareData.ASectionList.FindIndex(item => rpScrewDimRefEY > Math.Round(item.BottomLine.StartPoint.CustomerPoint.Y, 1));

                                                            List<BoardSectionItem> rpScrewBList = AssemblyShareData.ASectionList.GetRange(rpScrewBeginBIndex, rpScrewEndBIndex - rpScrewBeginBIndex + 1);
                                                            double toochDimRL = RPItem.ToochInfo.toochParam.ToochDimPart.RLine.Length;
                                                            double toochDimLL = RPItem.ToochInfo.toochParam.ToochDimPart.LLine.Length;
                                                            double customRealH = toochDimRL > toochDimLL ? toochDimRL : toochDimLL;
                                                            customRealH = Math.Round(customRealH, 1);
                                                            RPScrewItem.TheoryScrewH = ComputedUtils.RepScrewItemLRule(customRealH);
                                                            //if (rpScrewBList.Count > 0-5
                                                            //{
                                                            //    //BoardSectionItem rpFirstB = rpScrewBList.First();
                                                            //    // customRealH = rpFirstB.PlateThick;
                                                            //    //double rpFirstBEndPointY = rpFirstB.OverheadLine.StartPoint.CustomerPoint.Y;
                                                            //    ////按标准
                                                            //    //if (rpFirstBEndPointY > rpScrewDimRefEY)
                                                            //    //{
                                                            //    //    //double RSDY = RPItem.ToochInfo.toochParam.ToochDimPart.RLine.StartPoint.CustomerPoint.Y;
                                                            //    //    //double LSDY = RPItem.ToochInfo.toochParam.ToochDimPart.LLine.StartPoint.CustomerPoint.Y;
                                                            //    //    //double toochRefSY = RSDY > LSDY ? RSDY : LSDY;
                                                                    
                                                            //    //    //customRealH = toochRefSY - rpFirstBEndPointY;
                                                            //    //}
                                                            //    RPScrewItem.TheoryScrewH = ComputedUtils.RepScrewItemLRule(customRealH);
                                                            //}
                                                        }
                                                    }

                                                    //TheoryH = Fangtie(& orver) ~ Pass Board - epBoard + local 5 or 0
                                                    //No Cut off
                                                    if (!HasCutOffF)
                                                    {
                                                        double fangtieThick = AssemblyShareData.ASectionList.Find(item => item.BoardCode.Equals("fangtie")).PlateThick;
                                                        double epBoardThick = AssemblyShareData.ASectionList.FindLast(item => item.BoardCode.Equals("epBoard")).PlateThick;
                                                        RPItem.TheoryH = fangtieThick + RAbovefangtieBoardList.Sum(item => item.PlateThick) - epBoardThick;
                                                        RPItem.TheoryH = ComputedUtils.RPTheoryLRepRule(RPItem.TheoryH);
                                                    }
                                                    List<CSinglePartItem> RPDimPartList = CTempPRList[i].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.Dim);
                                                    RPItem.Dim = RPDimPartList.Select(item => item.XLength).First();
                                                    RPItem.TD = (int)CTempPRList[i].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD).Select(item => item.XLength).First();
                                                    double highFreAVX = RPDimPartList.Select(item => item.AVSplitCX).ToList().GroupBy(x => x).OrderByDescending(g => g.Count()).First().Key;
                                                    double AVCustomerCX = RPDimPartList.Select(item => item.AVCustomerCX).ToList().GroupBy(x => x).OrderByDescending(g => g.Count()).First().Key;
                                                    RPItem.AssembleCenterPointX = highFreAVX;
                                                    RPItem.AVCustomerCX = AVCustomerCX;
                                                    RPItem.TDPosType = InBoardPosType.BoardDown;
                                                    if (InBoardList.Count > 0)
                                                    {
                                                        RPItem.TDBoard = InBoardList[InBoardList.Count - 1];
                                                        InBoardList.RemoveAt(InBoardList.Count - 1);
                                                        if (InBoardList.Count > 0)
                                                            RPItem.ItemDimThroughHBList = InBoardList;
                                                    }
                                                    double TH = CTempPRList[i].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD).Select(item => item.YLength).Distinct().Max();
                                                    RPItem.TH = Convert.ToDecimal(TH);
                                                    // RP TO EDIT 
                                                    CU.RPTransToProcessData(RPItem);
                                                    RPItem.TVCPX = CTempPRList[i].CenterPoint.CustomerPoint.X;
                                                    if (Strategy.Equals("PLANA"))
                                                    {
                                                        RPItem.RelScrewHoleList = CTempPRList[i].RelScrewHoleList;
                                                        RPItem.ItemNum = RPItem.RelScrewHoleList.Count;
                                                        RPScrewItem.ItemNum = RPItem.ItemNum;
                                                    }
                                                    if (Strategy.Equals("PLANB"))
                                                    {
                                                        RPItem.RelScrewHoleList = TVRPHoleList;
                                                        RPItem.ItemNum = TVRPHoleList.Count;
                                                        RPScrewItem.ItemNum = RPItem.ItemNum;
                                                    }
                                                    RefHoleCenterSplitInfo SInfo = TranRefCHoleData(RPItem.ItemNameType, RPItem.RelScrewHoleList);
                                                    RPItem.HSplitInfo = SInfo;
                                                    //Judge Pass stBoard
                                                    if (RPItem.ItemDimThroughHBList.Count > 0)
                                                    {
                                                        int stIndex = RPItem.ItemDimThroughHBList.FindIndex(item => item.BoardCode.Equals("stBoard"));
                                                        if (stIndex != -1)
                                                            ShareItemBoardShipInfo.extraShipInfo.rpOverSpFlag = true;
                                                    }
                                                    if (RPItem.TDBoard.BoardUID != null)
                                                        if (RPItem.TDBoard.BoardCode.Equals("stBoard"))
                                                            ShareItemBoardShipInfo.extraShipInfo.rpOverSpFlag = true;
                                                    RPItem.ItemCode = "ReturnPin";
                                                    if (RPScrewItem.ItemNameType != DItemNameType.NONE)
                                                        ShareItemData.ItemList.Add(RPScrewItem);
                                                    ShareItemData.ItemList.Add(RPItem);
                                                }
                                            }
                                        }

                                        List<SingleItem> deduceRPScrewMesonList = new List<SingleItem>();
                                        //Find RP Screw Mesons
                                        List<SingleItem> rpList = ShareItemData.ItemList.FindAll(item => item.ItemCode.Equals("ReturnPin"));
                                        if (rpList.Count > 0)
                                        {
                                            int fangtieIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("fangtie"));
                                            if(fangtieIndex != -1)
                                            {
                                                int afterFIndex = fangtieIndex - 1;
                                                if(afterFIndex >= 0)
                                                {
                                                    double lowbY = AssemblyShareData.ASectionList[afterFIndex].BottomLine.StartPoint.CustomerPoint.Y;
                                                    for (int mi = 0; mi < rpList.Count; mi++)
                                                    {
                                                        List<CSinglePartItem> RPSMesonsItemVList = new List<CSinglePartItem>();
                                                        double refRPDim = rpList[mi].Dim;
                                                        double refX = Math.Round(rpList[mi].AssembleCenterPointX, 1);
                                                        //through Board Find RP Meson
                                                        List<BoardSectionItem> rpThroughBList =  rpList[mi].ItemDimThroughHBList;
                                                        if(rpThroughBList.Count > 0)
                                                        {
                                                            double cusBMaxY = rpThroughBList.First().OverheadLine.StartPoint.CustomerPoint.Y;
                                                            double cusBMinY = rpThroughBList.Last().OverheadLine.StartPoint.CustomerPoint.Y;
                                                            List<MixedCAD_Line> RPMVLines = new List<MixedCAD_Line>();
                                                            List<MixedCAD_Line> RPMOBLines = new List<MixedCAD_Line>();
                                                            List<double> targetVLineKeys = AVLineYDic.Keys.ToList().FindAll(item => cusBMinY <= Math.Round(item, 0) && Math.Round(item, 0) <= cusBMaxY);
                                                            if (targetVLineKeys.Count > 0)
                                                                targetVLineKeys.ForEach(key => RPMVLines.AddRange(AVLineYDic[key]));

                                                            List<double> targetOBLineKeys = OBLineYDic.Keys.ToList().FindAll(item => cusBMinY <= Math.Round(item, 0) && Math.Round(item, 0) <= cusBMaxY);
                                                            if (targetOBLineKeys.Count > 0)
                                                                targetOBLineKeys.ForEach(key => RPMOBLines.AddRange(OBLineYDic[key]));

                                                            if (RPMVLines.Count > 0)
                                                            {
                                                                for (int i = 0; i < RPMVLines.Count - 1; i++)
                                                                {
                                                                    for (int j = 1; j < RPMVLines.Count; j++)
                                                                    {
                                                                        if (j > i)
                                                                        {
                                                                            double tempDim = Math.Round(Math.Abs(RPMVLines[i].StartPoint.CustomerPoint.X - RPMVLines[j].StartPoint.CustomerPoint.X), 1);
                                                                            if (tempDim > refRPDim)
                                                                            {
                                                                                double TwoLineSplitAgvCX = Math.Round((RPMVLines[i].StartPoint.CustomerPoint.X + RPMVLines[j].StartPoint.CustomerPoint.X) / 2, 1);
                                                                                Boolean F = refX == TwoLineSplitAgvCX;
                                                                                if (F)
                                                                                {
                                                                                    CSinglePartItem maybeRPScrewMesonsItem = new CSinglePartItem();
                                                                                    maybeRPScrewMesonsItem.AVSplitCX = refX;
                                                                                    maybeRPScrewMesonsItem.ItemType = ItemPartCodeType.Dim;
                                                                                    maybeRPScrewMesonsItem.LLine = RPMVLines[i];
                                                                                    maybeRPScrewMesonsItem.RLine = RPMVLines[j];
                                                                                    maybeRPScrewMesonsItem.XLength = tempDim;
                                                                                    maybeRPScrewMesonsItem.YLength = Math.Round(Math.Abs(RPMVLines[i].StartPoint.CustomerPoint.Y - RPMVLines[i].EndPoint.CustomerPoint.Y), 0);
                                                                                    RPSMesonsItemVList.Add(maybeRPScrewMesonsItem);
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }

                                                            }

                                                            //Filter
                                                            if (RPSMesonsItemVList.Count > 0)
                                                            {
                                                                CSinglePartItem targetRPMesonPart = new CSinglePartItem();
                                                                if (RPSMesonsItemVList.Count > 0)
                                                                {
                                                                    double minXL = RPSMesonsItemVList.Select(item => item.XLength).Min();
                                                                    targetRPMesonPart = RPSMesonsItemVList.FindAll(item => item.XLength == minXL).First();
                                                                }
                                                                else
                                                                    targetRPMesonPart = RPSMesonsItemVList.First();

                                                                // Process 竖线 合并倒角 介子有倒角特征
                                                                if (RPMOBLines.Count > 0)
                                                                {
                                                                    MixedCAD_Line RLine = targetRPMesonPart.RLine;
                                                                    MixedCAD_Line LLine = targetRPMesonPart.LLine;
                                                                    // TO EDIT 
                                                                    for (int i = 0; i < RPMOBLines.Count; i++)
                                                                    {
                                                                        LineJoinType targetLType = ComputedUtils.JudgeTOLineConn(LLine, RPMOBLines[i]);
                                                                        Boolean LF = targetLType != LineJoinType.None;
                                                                        if (LF)
                                                                            ComputedUtils.AssSegmentTOLineConn(targetLType, LLine, RPMOBLines[i]);

                                                                        LineJoinType targetRType = ComputedUtils.JudgeTOLineConn(RLine, RPMOBLines[i]);
                                                                        Boolean RF = targetRType != LineJoinType.None;
                                                                        if (RF)
                                                                            ComputedUtils.AssSegmentTOLineConn(targetRType, RLine, RPMOBLines[i]);
                                                                    }

                                                                    if (LLine.SPChamferFlag)
                                                                    {
                                                                        LLine.Length += Math.Abs(LLine.SCLine.StartPoint.CustomerPoint.X - LLine.SCLine.EndPoint.CustomerPoint.X);
                                                                        LLine.StartPoint.CustomerPoint.X -= Math.Abs(LLine.SCLine.StartPoint.CustomerPoint.X - LLine.SCLine.EndPoint.CustomerPoint.X);
                                                                    }
                                                                    if (LLine.EPChamferFlag)
                                                                    {
                                                                        LLine.Length += Math.Abs(LLine.ECLine.StartPoint.CustomerPoint.X - LLine.ECLine.EndPoint.CustomerPoint.X);
                                                                        LLine.EndPoint.CustomerPoint.X += Math.Abs(LLine.ECLine.StartPoint.CustomerPoint.X - LLine.ECLine.EndPoint.CustomerPoint.X);
                                                                    }
                                                                    LLine.Length = Math.Round(LLine.Length, 1);
                                                                    if (RLine.SPChamferFlag)
                                                                    {
                                                                        RLine.Length += Math.Abs(RLine.SCLine.StartPoint.CustomerPoint.X - RLine.SCLine.EndPoint.CustomerPoint.X);
                                                                        RLine.StartPoint.CustomerPoint.X -= Math.Abs(RLine.SCLine.StartPoint.CustomerPoint.X - RLine.SCLine.EndPoint.CustomerPoint.X);
                                                                    }
                                                                    if (RLine.EPChamferFlag)
                                                                    {
                                                                        RLine.Length += Math.Abs(RLine.ECLine.StartPoint.CustomerPoint.X - RLine.ECLine.EndPoint.CustomerPoint.X);
                                                                        RLine.EndPoint.CustomerPoint.X += Math.Abs(RLine.ECLine.StartPoint.CustomerPoint.X - RLine.ECLine.EndPoint.CustomerPoint.X);
                                                                    }
                                                                    RLine.Length = Math.Round(RLine.Length, 1);
                                                                }
                                                                //回针介子
                                                                SingleItem targetRPMesonItem = new SingleItem();
                                                                targetRPMesonItem.ItemNameType = DItemNameType.ReturnPinScrewMeson;
                                                                targetRPMesonItem.ItemCode = "ReturnPinScrewMeson";
                                                                targetRPMesonItem.ItemNum = rpList[mi].ItemNum;
                                                                targetRPMesonItem.MatchScrewHole.CenterPoint = new MixedCAD_Point();
                                                                targetRPMesonItem.MatchScrewHole.CenterPoint.CustomerPoint.X = targetRPMesonPart.AVSplitCX;
                                                                targetRPMesonItem.Dim = targetRPMesonPart.XLength;
                                                                targetRPMesonItem.TheoryH = (int)targetRPMesonPart.LLine.Length;
                                                                targetRPMesonItem.RealH = (int)targetRPMesonPart.LLine.Length;
                                                                targetRPMesonItem.RealScrewH = (int)targetRPMesonPart.LLine.Length;
                                                                deduceRPScrewMesonList.Add(targetRPMesonItem);
                                                            }

                                                        }
                                                    }
                                                }
                                            }
                                            
                                        }

                                        //Dep
                                        if(deduceRPScrewMesonList.Count > 0)
                                        {
                                            List<SingleItem> resList = new List<SingleItem>();
                                            resList.Add(deduceRPScrewMesonList[0]);
                                            if (deduceRPScrewMesonList.Count > 1)
                                            {
                                                for (int i = 1; i < deduceRPScrewMesonList.Count; i++)
                                                {
                                                    Boolean NoSameFlag = resList.FindIndex(item => CU.JudgeDupRItem(item, deduceRPScrewMesonList[i])) == -1;
                                                    if (NoSameFlag)
                                                        resList.Add(deduceRPScrewMesonList[i]);
                                                }
                                            }
                                            if (resList.Count > 0)
                                                ShareItemData.ItemList.AddRange(resList);
                                        }
                                    }
                                }


                            }
                        }

                    }
                }
            }
            catch (Exception ex)
            {

            }
        }

        public static Boolean JudgeSameXVertical(MixedCAD_Line line1, MixedCAD_Line line2)
        {
            Boolean sameXF = Math.Round(line1.StartPoint.CustomerPoint.X, 1) == Math.Round(line2.StartPoint.CustomerPoint.X, 1);
            return sameXF;
        }

        public static MixedCAD_Line MergeSameVertical(MixedCAD_Line line1, MixedCAD_Line line2)
        {
            MixedCAD_Line Res = new MixedCAD_Line();
            Boolean F1 = line1.StartPoint.CustomerPoint.Y > line2.StartPoint.CustomerPoint.Y;
            Boolean F2 = line1.EndPoint.CustomerPoint.Y < line2.EndPoint.CustomerPoint.Y;
            if (F1)
            {
                Res.StartPoint = line1.StartPoint;
                Res.SPChamferFlag = line1.SPChamferFlag;
                if (line1.SPChamferFlag)
                    Res.SCLine = line1.SCLine;
            }
            else
            {
                Res.StartPoint = line2.StartPoint;
                Res.SPChamferFlag = line2.SPChamferFlag;
                if (line2.SPChamferFlag)
                    Res.SCLine = line2.SCLine;
            }

            if (F2)
            {
                Res.EndPoint = line1.EndPoint;
                Res.EPChamferFlag = line1.EPChamferFlag;
                if (line1.EPChamferFlag)
                    Res.ECLine = line1.ECLine;
            }
            else
            {
                Res.EndPoint = line2.EndPoint;
                Res.EPChamferFlag = line2.EPChamferFlag;
                if (line2.EPChamferFlag)
                    Res.ECLine = line2.ECLine;
            }

            Res.Length = Res.StartPoint.CustomerPoint.Y - Res.EndPoint.CustomerPoint.Y;
            if (Res.SPChamferFlag)
            {
                Res.Length += Math.Abs(Res.SCLine.StartPoint.CustomerPoint.X - Res.SCLine.EndPoint.CustomerPoint.X);
                Res.StartPoint.CustomerPoint.X -= Math.Abs(Res.SCLine.StartPoint.CustomerPoint.X - Res.SCLine.EndPoint.CustomerPoint.X);
            }
            if (Res.EPChamferFlag)
            {
                Res.Length += Math.Abs(Res.ECLine.StartPoint.CustomerPoint.X - Res.ECLine.EndPoint.CustomerPoint.X);
                Res.EndPoint.CustomerPoint.X += Math.Abs(Res.ECLine.StartPoint.CustomerPoint.X - Res.ECLine.EndPoint.CustomerPoint.X);
            }
            
            Res.Length = Math.Round(Res.Length, 1);
            return Res;
        }

        // F Half
        public static void RecognizeGP(int GPBushEndBoardIndex,Dictionary<double, List<MixedCAD_Line>> ItemTSLineYDic,
            Dictionary<double, List<MixedCAD_Line>> AVLineYDic,List<MixedCAD_Arc> AArcList, List<MixedCAD_Curve> ACurveList)
        {
            try
            {
                double? refAVCPX = null;
                //Merge One of Same GP All Part Info
                List<CSingleItem> CTempGPList = new List<CSingleItem>();
                //Assem View GP Item Part V Line Collection
                List<CSinglePartItem> GPItemVList = new List<CSinglePartItem>();
                //About GP Dim TD Board
                List<BoardSectionItem> AboutDimAndTDBoardList = new List<BoardSectionItem>();
                //About Bush Board Area Info 
                List<BoardSectionItem> AboutBushBoardList = new List<BoardSectionItem>();
                //GP Scope Board
                List<BoardSectionItem> GPScopeBoardList = new List<BoardSectionItem>();
                Boolean notTPF = CADCommonForm.MoldTypeStr.Equals("PP") || CADCommonForm.MoldTypeStr.Equals("SG");
                List<BoardSectionItem> BlueList = new List<BoardSectionItem>(AssemblyShareData.ASectionList);
                BlueList = BlueList.FindAll(item => !(item.BoardCode.Equals("fpBoard") || item.BoardCode.Equals("epBoard")));
                //Customer GP Real Center
                double? AVTDRealCenterX = null;
                //If Has Fangtie limit X scope 
                double? AllowLX = null;
                double? AllowRX = null;
                if (FangtieShareData.HasLRF)
                {
                    AllowLX = (double)FangtieShareData.FLXInfo.SplitX + 30;
                    AllowRX = (double)FangtieShareData.FRXInfo.SplitX - 30;
                }
                int mayRefBIndex = -1;
                // TD Bush Length Ref about A B stBoard 1/5
                double? TDBushTDrefY = null;
                mayRefBIndex = CU.GetOneBoardIndex("aBoard");
                if (mayRefBIndex != -1)
                    TDBushTDrefY = AssemblyShareData.ASectionList[mayRefBIndex].PlateThick / 2;
                else
                {
                    mayRefBIndex = CU.GetOneBoardIndex("bBoard");
                    if (mayRefBIndex != -1)
                        TDBushTDrefY = AssemblyShareData.ASectionList[mayRefBIndex].PlateThick / 2;
                    else
                    {
                        mayRefBIndex = CU.GetOneBoardIndex("stBoard");
                        if (mayRefBIndex != -1)
                            TDBushTDrefY = AssemblyShareData.ASectionList[mayRefBIndex].PlateThick / 2;
                    }
                }

                //Limit find GP Dim TD Bush Area Scope
                Boolean TPF = CADCommonForm.MoldTypeStr.Equals("TP");
                if (!TPF)
                {
                    int startBoardIndex = BlueList.FindIndex(item => item.BoardCode.Equals("aBoard"));
                    List<BoardSectionItem> rpsList = BlueList.FindAll(item => item.BoardCode.Equals("rspBoard"));
                    if (rpsList.Count > 1)
                        startBoardIndex = BlueList.FindLastIndex(item => item.BoardCode.Equals("rspBoard"));
                    if (startBoardIndex != -1)
                    {
                        AboutBushBoardList = BlueList.GetRange(startBoardIndex, BlueList.Count - startBoardIndex);
                        AboutDimAndTDBoardList = BlueList.GetRange(startBoardIndex, BlueList.Count - startBoardIndex);
                    }
                }
                //TP
                else
                {
                    //Dim TD Find from cpBoard
                    int cpBoardIndex = BlueList.FindIndex(item => item.BoardCode.Equals("cpBoard"));
                    //Bush Find from rspBoard
                    int rspBoardIndex = BlueList.FindIndex(item => item.BoardCode.Equals("rspBoard"));
                    if (rspBoardIndex != -1)
                    {
                        if (GPBushEndBoardIndex != -1 && GPBushEndBoardIndex > rspBoardIndex)
                            AboutBushBoardList = BlueList.GetRange(rspBoardIndex, GPBushEndBoardIndex - rspBoardIndex + 1);
                        else
                            AboutBushBoardList = BlueList.GetRange(rspBoardIndex, BlueList.Count - rspBoardIndex);
                    }
                    else
                    {
                        if (GPBushEndBoardIndex != -1)
                            AboutBushBoardList = BlueList.GetRange(0, GPBushEndBoardIndex + 1);
                        else
                            AboutBushBoardList = BlueList.GetRange(0, AboutBushBoardList.Count - 1);
                    }
                    if (cpBoardIndex != -1)
                        AboutDimAndTDBoardList = BlueList.GetRange(cpBoardIndex, BlueList.Count - cpBoardIndex);
                }

                //GP Arc that conforms to the outer profile of the guide post TO EDIT 
                List<MixedCAD_Arc> GPCandiArcList = new List<MixedCAD_Arc>();
                if (AboutDimAndTDBoardList.Count > 0 && AArcList.Count > 0)
                {
                    double GPCircleMaxY = AboutDimAndTDBoardList.Max(item => Math.Round(item.OverheadLine.StartPoint.CustomerPoint.Y, 0));
                    double GPCircleMinY = AboutDimAndTDBoardList.Min(item => Math.Round(item.BottomLine.EndPoint.CustomerPoint.Y, 0));
                    GPCandiArcList = AArcList.FindAll(item => GPCircleMinY <= Math.Round(item.CenterPoint.CustomerPoint.Y, 0)
                    && Math.Round(item.CenterPoint.CustomerPoint.Y, 0) <= GPCircleMaxY);
                    if (CADCommonForm.MoldTypeStr.Equals("PP"))
                    {
                        if (FangtieShareData.HasLRF)
                        {
                            if (FangtieShareData.SPAnotherFX == FangtieShareData.FLXInfo.SplitX)
                                GPCandiArcList = GPCandiArcList.FindAll(item => item.StartPoint.CustomerPoint.X > AllowRX);
                            if (FangtieShareData.SPAnotherFX == FangtieShareData.FRXInfo.SplitX)
                                GPCandiArcList = GPCandiArcList.FindAll(item => item.StartPoint.CustomerPoint.X < AllowLX);
                        }
                    }
                }
                List<ScrewHole> GPList = HoleCandidateShareData.GPScrewCList;
                ComputedUtils.SwitchTVHoleCoorType(GPList);
                if (AboutBushBoardList.Count > 0 && GPList.Count > 0)
                {
                    //TVLine
                    List<MixedCAD_Line> TSGPLines = new List<MixedCAD_Line>();
                    //(GP Outer Contour Feature) fit Dim TVLine
                    List<MixedCAD_Line> CDimTSLineList = new List<MixedCAD_Line>();
                    //Dim TD VLine
                    List<MixedCAD_Line> CandDimTDGPVLines = new List<MixedCAD_Line>();
                    //Begin Collection Info (Dim And TD)
                    for (int z = 0; z < AboutDimAndTDBoardList.Count; z++)
                    {
                        double AboutDimTDBMaxY = Math.Round(AboutDimAndTDBoardList[z].OverheadLine.UseStartPoint.Y, 0);
                        double AboutDimTDBMinY = Math.Round(AboutDimAndTDBoardList[z].BottomLine.UseStartPoint.Y, 0);
                        List<double> BoardVLineKeys = AVLineYDic.Keys.ToList().FindAll(item => AboutDimTDBMinY <= Math.Round(item, 0)
                        && Math.Round(item, 0) <= AboutDimTDBMaxY);
                        if (BoardVLineKeys != null)
                        {
                            BoardVLineKeys.ForEach(key => CandDimTDGPVLines.AddRange(AVLineYDic[key]));
                            BoardVLineKeys.Clear();
                        }
                        List<double> BoardTSLineKeys = ItemTSLineYDic.Keys.ToList().FindAll(item => AboutDimTDBMinY <= Math.Round(item, 0)
                        && Math.Round(item, 0) <= AboutDimTDBMaxY);
                        if (BoardTSLineKeys != null)
                        {
                            BoardTSLineKeys.ForEach(key => TSGPLines.AddRange(ItemTSLineYDic[key]));
                            BoardTSLineKeys.Clear();
                        }
                    }

                    //Divide Area
                    if (CADCommonForm.MoldTypeStr.Equals("PP"))
                    {
                        if (FangtieShareData.HasLRF)
                        {
                            if (FangtieShareData.SPAnotherFX == FangtieShareData.FLXInfo.SplitX)
                            {
                                CandDimTDGPVLines = CandDimTDGPVLines.FindAll(item => item.StartPoint.UsePoint.X > AllowRX);
                                TSGPLines = TSGPLines.FindAll(item => item.StartPoint.UsePoint.X > AllowRX);
                            }
                            if (FangtieShareData.SPAnotherFX == FangtieShareData.FRXInfo.SplitX)
                            {
                                CandDimTDGPVLines = CandDimTDGPVLines.FindAll(item => item.StartPoint.UsePoint.X < AllowLX);
                                TSGPLines = TSGPLines.FindAll(item => item.StartPoint.UsePoint.X < AllowLX);
                            }
                        }
                    }
                    else
                    {
                        if (FangtieShareData.HasLRF)
                        {
                            CandDimTDGPVLines = CandDimTDGPVLines.FindAll(item => item.StartPoint.UsePoint.X < AllowLX 
                            || item.StartPoint.UsePoint.X > AllowRX);
                            TSGPLines = TSGPLines.FindAll(item => item.StartPoint.UsePoint.X < AllowLX 
                            || item.StartPoint.UsePoint.X > AllowRX);
                        }
                    }

                    //Merge VLine
                    if (CandDimTDGPVLines.Count > 1)
                        CandDimTDGPVLines = ComputedUtils.MergeSimilarXVLineList(CandDimTDGPVLines);

                    if (CandDimTDGPVLines.Count > 1)
                    {
                        if (GPList.Count > 0)
                        {
                            List<double> GPXList = GPList.Select(item => item.CenterPoint.TransSplitPoint.X).Distinct().ToList();
                            double refDim = GPList.First().Dim;
                            double refTD = GPList.First().TD;
                            for (int i = 0; i < CandDimTDGPVLines.Count - 1; i++)
                            {
                                for (int j = 1; j < CandDimTDGPVLines.Count; j++)
                                {
                                    if (j > i)
                                    {
                                        for (int k = 0; k < GPXList.Count; k++)
                                        {
                                            double TempDim = Math.Abs(CandDimTDGPVLines[i].StartPoint.UsePoint.X - CandDimTDGPVLines[j].StartPoint.UsePoint.X);
                                            //Approximate center symmetry calculation error +- 5
                                            double TwoLineSplitAgvCX = Math.Round((CandDimTDGPVLines[i].StartPoint.UsePoint.X +
                                                CandDimTDGPVLines[j].StartPoint.UsePoint.X) / 2, 1);
                                            double TwoLineCustomerAgvCX = Math.Round((CandDimTDGPVLines[i].StartPoint.CustomerPoint.X +
                                                CandDimTDGPVLines[j].StartPoint.CustomerPoint.X) / 2, 1);
                                            double TargetCenterX = Math.Round(GPXList[k], 1);
                                            double LX = TargetCenterX - 5;
                                            double RX = TargetCenterX + 5;
                                            if (LX <= TwoLineSplitAgvCX && TwoLineSplitAgvCX <= RX)
                                            {
                                                CSinglePartItem GPItem = new CSinglePartItem();
                                                if (refDim - 0.02 <= TempDim && TempDim <= refDim + 0.02)
                                                {
                                                    //Dim
                                                    GPItem.ItemType = ItemPartCodeType.Dim;
                                                    GPItem.LLine = CandDimTDGPVLines[i];
                                                    GPItem.RLine = CandDimTDGPVLines[j];
                                                    GPItem.XLength = TempDim;
                                                    GPItem.YLength = Math.Round(CandDimTDGPVLines[i].Length, 0);
                                                    GPItem.AVSplitCX = TwoLineSplitAgvCX;
                                                    GPItem.AVCustomerCX = TwoLineCustomerAgvCX;
                                                    GPItem.TVCPX = TargetCenterX;
                                                    GPItemVList.Add(GPItem);
                                                }
                                                if (refTD - 1 <= TempDim && TempDim <= refTD + 1)
                                                {
                                                    Boolean LengthF = Math.Round(CandDimTDGPVLines[i].Length, 1) == Math.Round(CandDimTDGPVLines[j].Length, 1);
                                                    if (LengthF)
                                                    {
                                                        //TD
                                                        GPItem.ItemType = ItemPartCodeType.TD;
                                                        GPItem.LLine = CandDimTDGPVLines[i];
                                                        GPItem.RLine = CandDimTDGPVLines[j];
                                                        GPItem.XLength = TempDim;
                                                        GPItem.YLength = Math.Round(Math.Abs(CandDimTDGPVLines[i].Length), 0);
                                                        GPItem.AVSplitCX = TwoLineSplitAgvCX;
                                                        GPItem.AVCustomerCX = TwoLineCustomerAgvCX;
                                                        GPItem.TVCPX = TargetCenterX;
                                                        GPItemVList.Add(GPItem);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            if (GPItemVList.Count > 0)
                            {
                                for (int i = 0; i < GPItemVList.Count; i++)
                                {
                                    double refX = GPItemVList[i].TVCPX;
                                    int tIndex = GPList.FindIndex(item => Math.Round(item.CenterPoint.TransSplitPoint.X, 1) == refX);
                                    if (tIndex != -1)
                                        GPItemVList[i].MatchScrewHole = GPList[tIndex];
                                }
                            }
                        }
                    }

                    //Filter SP X disturb
                    int spIndex = ShareItemData.ItemList.FindIndex(item => item.ItemNameType == DItemNameType.SupportPin
                    || item.ItemNameType == DItemNameType.NoNozzleMesonSupportPin);
                    if (spIndex != -1)
                    {
                        double SPCX = ShareItemData.ItemList[spIndex].TVCPX;
                        List<CSinglePartItem> operPartItemList = (List<CSinglePartItem>)ConvertUtils.DeepCopyObject(GPItemVList);
                        operPartItemList = operPartItemList.FindAll(item => item.TVCPX != SPCX);
                        List<CSinglePartItem> operDimPartItemList = operPartItemList.FindAll(item => item.ItemType == ItemPartCodeType.Dim).ToList();
                        if (operDimPartItemList.Count > 0)
                        {
                            List<double> dimPartXList = operDimPartItemList.Select(item => item.TVCPX).Distinct().ToList();
                            double refX = dimPartXList.GroupBy(n => n).OrderByDescending(g => g.Count()).First().ToList()[0];
                            operPartItemList = operPartItemList.FindAll(item => item.TVCPX == refX);
                            GPItemVList = operPartItemList;
                        }
                    }
                    else
                    {
                        List<double> dimPartXList = GPItemVList.Select(item => item.TVCPX).Distinct().ToList();
                        double refX = dimPartXList.GroupBy(n => n).OrderByDescending(g => g.Count()).First().ToList()[0];
                        GPItemVList = GPItemVList.FindAll(item => item.TVCPX == refX);
                    }

                    List<CSinglePartItem> GPTDList = GPItemVList.FindAll(item => item.ItemType == ItemPartCodeType.TD);
                    if (GPTDList.Count > 0)
                    {
                        //TD filter far
                        GPTDList = GPTDList.FindAll(item => CU.JudgeTwoYLineNoTooOverDis(item.LLine, item.RLine));
                        if (TDBushTDrefY != null)
                        {
                            GPTDList = GPTDList.FindAll(item => item.YLength <= (double)TDBushTDrefY);
                            GPItemVList = GPItemVList.FindAll(item => item.ItemType == ItemPartCodeType.Dim);
                        }
                    }

                    if (GPTDList.Count > 0)
                    {
                        double computedTDX = CU.FindItemAVSplitCX(GPTDList);
                        AVTDRealCenterX = computedTDX;
                        GPTDList = GPTDList.FindAll(item => item.AVSplitCX == computedTDX).ToList();
                        GPItemVList = GPItemVList.FindAll(item => item.AVSplitCX == computedTDX).ToList();
                        GPItemVList.AddRange(GPTDList);
                    }

                    //Bush V Candidate Line
                    List<MixedCAD_Line> CandBushGPVLines = new List<MixedCAD_Line>();
                    for (int z = 0; z < AboutBushBoardList.Count; z++)
                    {
                        double AboutBushBMaxY = Math.Round(AboutBushBoardList[z].OverheadLine.UseStartPoint.Y, 0);
                        double AboutBushBMinY = Math.Round(AboutBushBoardList[z].BottomLine.UseStartPoint.Y, 0);
                        List<double> BoardVLineKeys = AVLineYDic.Keys.ToList().FindAll(item => AboutBushBMinY <= Math.Round(item, 0)
                        && Math.Round(item, 0) <= AboutBushBMaxY);
                        if (BoardVLineKeys != null)
                        {
                            BoardVLineKeys.ForEach(key => CandBushGPVLines.AddRange(AVLineYDic[key]));
                            BoardVLineKeys.Clear();
                        }
                        List<double> BoardTSLineKeys = ItemTSLineYDic.Keys.ToList().FindAll(item => AboutBushBMinY <= Math.Round(item, 0)
                        && Math.Round(item, 0) <= AboutBushBMaxY);
                        if (BoardTSLineKeys != null)
                        {
                            BoardTSLineKeys.ForEach(key => TSGPLines.AddRange(ItemTSLineYDic[key]));
                            BoardTSLineKeys.Clear();
                        }
                    }

                    //Merge BushVLine
                    if (CandBushGPVLines.Count > 1)
                        CandBushGPVLines = ComputedUtils.MergeSimilarXVLineList(CandBushGPVLines);
                    if (CADCommonForm.MoldTypeStr.Equals("PP"))
                    {
                        if (FangtieShareData.HasLRF)
                        {
                            if (FangtieShareData.SPAnotherFX == FangtieShareData.FLXInfo.SplitX)
                            {
                                CandBushGPVLines = CandBushGPVLines.FindAll(item => item.StartPoint.TransSplitPoint.X > AllowRX);
                                TSGPLines = TSGPLines.FindAll(item => item.StartPoint.TransSplitPoint.X > AllowRX);
                            }
                            if (FangtieShareData.SPAnotherFX == FangtieShareData.FRXInfo.SplitX)
                            {
                                CandBushGPVLines = CandBushGPVLines.FindAll(item => item.StartPoint.TransSplitPoint.X < AllowLX);
                                TSGPLines = TSGPLines.FindAll(item => item.StartPoint.TransSplitPoint.X < AllowLX);
                            }
                        }
                    }
                    else
                    {
                        if (FangtieShareData.HasLRF)
                        {
                            CandBushGPVLines = CandBushGPVLines.FindAll(item => item.StartPoint.TransSplitPoint.X < AllowLX 
                            || item.StartPoint.TransSplitPoint.X > AllowRX);
                            TSGPLines = TSGPLines.FindAll(item => item.StartPoint.TransSplitPoint.X < AllowLX 
                            || item.StartPoint.TransSplitPoint.X > AllowRX);
                        }
                    }

                    if (CandBushGPVLines.Count > 0 && AVTDRealCenterX != null)
                    {
                        double GPRefCenterX = (double)AVTDRealCenterX;
                        ScrewHole refScrewHole = GPList[0];
                        for (int i = 0; i < CandBushGPVLines.Count - 1; i++)
                        {
                            for (int j = 1; j < CandBushGPVLines.Count; j++)
                            {
                                if (j > i)
                                {
                                    double TempDim = Math.Abs(CandBushGPVLines[i].StartPoint.CustomerPoint.X - CandBushGPVLines[j].StartPoint.CustomerPoint.X);
                                    double TwoLineSplitAgvCX = Math.Round((CandBushGPVLines[i].StartPoint.TransSplitPoint.X
                                        + CandBushGPVLines[j].StartPoint.TransSplitPoint.X) / 2, 1);
                                    double LX = TwoLineSplitAgvCX - 5;
                                    double RX = TwoLineSplitAgvCX + 5;
                                    double TwoLineCustomerAgvCX = Math.Round((CandBushGPVLines[i].StartPoint.CustomerPoint.X +
                                                CandBushGPVLines[j].StartPoint.CustomerPoint.X) / 2, 1);
                                    Boolean satF = LX <= Math.Round(GPRefCenterX, 1) && Math.Round(GPRefCenterX, 1) <= RX;
                                    if (satF)
                                    {
                                        CSinglePartItem GPItem = new CSinglePartItem();
                                        if (refScrewHole.BushSize - 2 - 0.01 <= TempDim && TempDim <= refScrewHole.BushSize + 2 + 0.01)
                                        {
                                            GPItem.ItemType = ItemPartCodeType.BushSize;
                                            GPItem.LLine = CandBushGPVLines[i];
                                            GPItem.RLine = CandBushGPVLines[j];
                                            GPItem.XLength = TempDim;
                                            GPItem.YLength = Math.Round(Math.Abs(CandBushGPVLines[i].StartPoint.CustomerPoint.Y -
                                                CandBushGPVLines[i].EndPoint.CustomerPoint.Y), 0);
                                            GPItem.AVSplitCX = TwoLineSplitAgvCX;
                                            GPItem.AVCustomerCX = TwoLineCustomerAgvCX;
                                            GPItem.TVCPX = GPRefCenterX;
                                            GPItem.MatchScrewHole = refScrewHole;
                                            GPItemVList.Add(GPItem);
                                        }
                                        if (refScrewHole.BushTD - 2 - 0.01 <= TempDim && TempDim <= refScrewHole.BushTD + 2 + 0.01)
                                        {
                                            GPItem.ItemType = ItemPartCodeType.BushTD;
                                            GPItem.LLine = CandBushGPVLines[i];
                                            GPItem.RLine = CandBushGPVLines[j];
                                            GPItem.XLength = TempDim;
                                            GPItem.YLength = Math.Round(Math.Abs(CandBushGPVLines[i].StartPoint.CustomerPoint.Y -
                                                CandBushGPVLines[i].EndPoint.CustomerPoint.Y), 0);
                                            GPItem.AVSplitCX = TwoLineSplitAgvCX;
                                            GPItem.AVCustomerCX = TwoLineCustomerAgvCX;
                                            GPItem.TVCPX = GPRefCenterX;
                                            GPItem.MatchScrewHole = refScrewHole;
                                            GPItemVList.Add(GPItem);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    //Collection Bush Info
                    List<CSinglePartItem> CRBushTDList = GPItemVList.FindAll(item => item.ItemType == ItemPartCodeType.BushTD);
                    //Bush T Value
                    List<double> BushTDValueList = new List<double>();
                    //BushTD Dis filter far ReSet
                    if (CRBushTDList.Count > 0)
                    {
                        CRBushTDList = CRBushTDList.Distinct(new CSinglePartItemComparer()).ToList();
                        CRBushTDList = CRBushTDList.FindAll(item => CU.JudgeTwoYLineNoTooOverDis(item.LLine, item.RLine));
                        GPItemVList = GPItemVList.FindAll(item => !(item.ItemType == ItemPartCodeType.BushTD));
                        GPItemVList.AddRange(CRBushTDList);
                        if (CRBushTDList.Count > 0)
                            BushTDValueList = CRBushTDList.Select(item => item.XLength).Distinct().ToList();
                    }
                    //BushTD Info
                    List<SingleBushTDPartItem> SureBushTDPartList = new List<SingleBushTDPartItem>();
                    if (CRBushTDList.Count > 0)
                    {
                        for (int i = 0; i < CRBushTDList.Count; i++)
                        {
                            double LSY = CRBushTDList[i].LLine.StartPoint.CustomerPoint.Y;
                            double LEY = CRBushTDList[i].LLine.EndPoint.CustomerPoint.Y;
                            double RSY = CRBushTDList[i].RLine.StartPoint.CustomerPoint.Y;
                            double REY = CRBushTDList[i].RLine.EndPoint.CustomerPoint.Y;
                            //probability More Higher
                            double TY = LSY < RSY ? LSY : RSY;
                            double BY = LEY > REY ? LEY : REY;
                            int BushTDIndex = AboutBushBoardList.FindIndex(Item => TY <= Item.OverheadLine.StartPoint.CustomerPoint.Y
                            && Item.BottomLine.StartPoint.CustomerPoint.Y <= BY);
                            if (BushTDIndex != -1)
                            {
                                SingleBushTDPartItem TempBushTDPart = new SingleBushTDPartItem();
                                //Compare Agv to Sure Installation mode
                                TempBushTDPart.BushTDBoard = AboutBushBoardList[BushTDIndex];
                                double BTDOY = TempBushTDPart.BushTDBoard.OverheadLine.StartPoint.CustomerPoint.Y;
                                double BTDBY = TempBushTDPart.BushTDBoard.BottomLine.StartPoint.CustomerPoint.Y;
                                double TempBushTDH = Math.Round(TY - BY, 0);
                                TempBushTDPart.H = TempBushTDH;
                                double AveBH = (BTDOY + BTDBY) / 2;
                                double AveBushTDH = (TY + BY) / 2;
                                if (AveBH < AveBushTDH)
                                    TempBushTDPart.BushTDPosType = InBoardPosType.BoardUp;
                                else
                                    TempBushTDPart.BushTDPosType = InBoardPosType.BoardDown;
                                SureBushTDPartList.Add(TempBushTDPart);
                            }
                        }
                        //Dis
                        SureBushTDPartList = SureBushTDPartList.Distinct(new SingleBushTDPartItemComparer()).ToList();
                    }
                    //Merge BushTD Info 
                    List<PartBushTDArgItem> MergeBushTDInfoList = CU.MergePartBushTDInfo(SureBushTDPartList);
                    //Bush TD Board UID
                    List<string> BushTDBoardUIDList = new List<string>();
                    if (MergeBushTDInfoList.Count > 0)
                        BushTDBoardUIDList = MergeBushTDInfoList.Select(item => item.BushTDBoard.BoardUID).ToList();
                    //收集导套直径相关的数据
                    List<CSinglePartItem> CRBushSizeList = GPItemVList.FindAll(item => item.ItemType == ItemPartCodeType.BushSize);
                    CRBushSizeList = CRBushSizeList.Distinct(new CSinglePartItemComparer()).ToList();
                    //导套直径横值信息
                    List<double> BushSizeValueList = new List<double>();
                    if (CRBushSizeList.Count > 0)
                        BushSizeValueList = CRBushSizeList.Select(item => item.XLength).Distinct().ToList();
                    //暂存 导套直径信息
                    List<BoardSectionItem> BushSizeBoardList = new List<BoardSectionItem>();
                    //Dis
                    if (CRBushSizeList.Count > 0)
                    {
                        List<CSinglePartItem> resList = new List<CSinglePartItem>();
                        resList.Add(CRBushSizeList[0]);
                        if (CRBushSizeList.Count > 1)
                        {
                            for (int i = 1; i < CRBushSizeList.Count; i++)
                            {
                                Boolean NoSameFlag = resList.FindIndex(item => CU.JudgeRepeatBushTDPart(item, CRBushSizeList[i])) == -1;
                                if (NoSameFlag)
                                    resList.Add(CRBushSizeList[i]);
                            }
                        }

                        //Filter
                        if (resList.Count > 0)
                            CRBushSizeList = resList.FindAll(item => ComputedUtils.FilterMismatchBushGroupLine(item.LLine, item.RLine));

                        //导套直径线段有可能连续穿过两块及两块以上的板 
                        for (int i = 0; i < CRBushSizeList.Count; i++)
                        {
                            double LSY = CRBushSizeList[i].LLine.StartPoint.CustomerPoint.Y;
                            double LEY = CRBushSizeList[i].LLine.EndPoint.CustomerPoint.Y;
                            double RSY = CRBushSizeList[i].RLine.StartPoint.CustomerPoint.Y;
                            double REY = CRBushSizeList[i].RLine.EndPoint.CustomerPoint.Y;
                            double TY = LSY < RSY ? LSY : RSY;
                            double BY = LEY > REY ? LEY : REY;
                            int FirstBoardIndex = AboutBushBoardList.FindLastIndex(item => TY <= item.OverheadLine.StartPoint.CustomerPoint.Y);
                            int SecondBoardIndex = AboutBushBoardList.FindIndex(item => item.BottomLine.StartPoint.CustomerPoint.Y <= BY);
                            if (FirstBoardIndex != -1 && SecondBoardIndex != -1 && SecondBoardIndex >= FirstBoardIndex)
                            {
                                List<BoardSectionItem> TempAreaBList = AboutBushBoardList.GetRange(FirstBoardIndex, SecondBoardIndex - FirstBoardIndex + 1);
                                if (TempAreaBList.Count > 0)
                                    BushSizeBoardList.AddRange(TempAreaBList);
                            }
                        }
                    }

                    if (BushSizeBoardList.Count > 0)
                        BushSizeBoardList = BushSizeBoardList.Distinct().ToList();

                    //导套托位板包含于导套外径板
                    if (MergeBushTDInfoList.Count > 0 && BushSizeBoardList.Count > 0)
                    {
                        List<string> BoardUIDList = MergeBushTDInfoList.Select(item => item.BushTDBoard.BoardUID).ToList();
                        if (BoardUIDList.Count > 0)
                        {
                            List<BoardSectionItem> depTempList = new List<BoardSectionItem>();
                            for (int depi = 0; depi < BoardUIDList.Count; depi++)
                            {
                                int depIndex = BushSizeBoardList.FindIndex(item => item.BoardUID.Equals(BoardUIDList[depi]));
                                if (depIndex != -1)
                                    BushSizeBoardList.RemoveAt(depIndex);
                            }
                        }
                    }

                    //除套外的其余部分(Dim/TD) 去重
                    GPItemVList = GPItemVList.FindAll(item => !(item.ItemType == ItemPartCodeType.BushSize
                    || item.ItemType == ItemPartCodeType.BushTD));
                    if (GPItemVList.Count > 0)
                    {
                        List<CSinglePartItem> resList = new List<CSinglePartItem>();
                        resList.Add(GPItemVList[0]);
                        if (GPItemVList.Count > 1)
                        {
                            for (int i = 1; i < GPItemVList.Count; i++)
                            {
                                Boolean NoSameFlag = resList.FindIndex(item => CU.JudgeEqualItemPart(item, GPItemVList[i])) == -1;
                                if (NoSameFlag)
                                    resList.Add(GPItemVList[i]);
                            }
                        }
                        GPItemVList = resList;
                    }

                    //Merge GP Dim TD Part
                    if (GPItemVList.Count > 0)
                    {
                        var GroupByList = GPItemVList.GroupBy(item => item.TVCPX);
                        foreach (var Item in GroupByList)
                        {
                            List<CSinglePartItem> ItemPartList = Item.ToList();
                            CSingleItem CItem = new CSingleItem();
                            //CItem.CenterPoint.CustomerPoint.X = Item.Key;
                            for (int i = 0; i < ItemPartList.Count; i++)
                            {
                                CItem.CenterPoint.CustomerPoint.X = ItemPartList[i].AVCustomerCX;
                                CItem.CenterPoint.TransSplitPoint.X = ItemPartList[i].AVSplitCX;
                                CItem.MatchScrewHole = ItemPartList[i].MatchScrewHole;
                                CItem.InfoList.Add(ItemPartList[i]);
                            }
                            CTempGPList.Add(CItem);
                        }
                    }

                    CTempGPList = CTempGPList.FindAll(item => item.InfoList.Select(info => info.ItemType).Distinct().ToList().Count > 1);
                    if (CTempGPList.Count > 0)
                    {
                        //RP isturb(回针有时候Dim和TD会和导柱一致)
                        BoardSectionItem LastepBoard = AssemblyShareData.ASectionList.FindLast(item => item.BoardCode.Equals("epBoard"));
                        if (LastepBoard != null)
                        {
                            double LX = LastepBoard.OverheadLine.StartPoint.TransSplitPoint.X;
                            double RX = LastepBoard.OverheadLine.EndPoint.TransSplitPoint.X;
                            for (int i = 0; i < CTempGPList.Count; i++)
                            {
                                Boolean CF = CU.JudgeItemPartFallOutInterval(CTempGPList[i].InfoList, LX, RX);
                                if (!CF)
                                {
                                    CTempGPList.RemoveAt(i);
                                    i++;
                                }
                            }
                        }
                    }

                    if (CTempGPList.Count > 0)
                        CTempGPList = CTempGPList.FindAll(item => item.InfoList.Select(info => info.ItemType).ToList().Count > 1);

                    //能识别出导柱
                    if (CTempGPList.Count > 0)
                    {
                        List<CSinglePartItem> AllRelatedBKVList = new List<CSinglePartItem>();
                        for (int i = 0; i < CTempGPList.Count; i++)
                            CTempGPList[i].RelScrewHoleList = GPList.FindAll(item =>
                                 (CTempGPList[i].MatchScrewHole.Dim - 0.01 <= item.Dim && item.Dim <= CTempGPList[i].MatchScrewHole.Dim + 0.01)
                                 &&
                                 (CTempGPList[i].MatchScrewHole.TD - 0.01 <= item.TD && item.TD <= CTempGPList[i].MatchScrewHole.TD + 0.01));

                        for (int i = 0; i < CTempGPList.Count; i++)
                        {
                            //托位和直径 相似的线段部位
                            List<CSinglePartItem> DimAndTDInfoList = CTempGPList[i].InfoList;
                            //简化型的避空会和托位近似 需要排除 一般在B板以下
                            if (TPF)
                            {
                                int bBoardIndex = AssemblyShareData.ASectionList.FindLastIndex(item => item.BoardCode.Equals("bBoard"));
                                if (bBoardIndex != -1)
                                {
                                    double BoardBY = Math.Round(AssemblyShareData.ASectionList[bBoardIndex].BottomLine.StartPoint.CustomerPoint.Y, 0);
                                    if (DimAndTDInfoList.Count > 0)
                                    {
                                        List<CSinglePartItem> tempDimList = DimAndTDInfoList.FindAll(item => item.ItemType
                                        == ItemPartCodeType.Dim).ToList();
                                        List<CSinglePartItem> tempTDList = DimAndTDInfoList.FindAll(item => item.ItemType
                                        == ItemPartCodeType.TD).ToList();
                                        DimAndTDInfoList.Clear();
                                        if (tempDimList.Count > 0)
                                            DimAndTDInfoList.AddRange(tempDimList);
                                        tempTDList = tempTDList.FindAll(item => item.LLine.EndPoint.CustomerPoint.Y >= BoardBY
                                        && item.RLine.EndPoint.CustomerPoint.Y >= BoardBY);
                                        if (tempTDList.Count > 0)
                                            DimAndTDInfoList.AddRange(tempTDList);
                                    }
                                }
                            }
                            if (DimAndTDInfoList.Count > 0)
                            {
                                //标准
                                List<int> StandradDimList = StandardShareScopeItemParam.GPSScrewDimList;
                                //Dim 的信息
                                CSinglePartItem DimPartItem = DimAndTDInfoList.Find(item => item.ItemType == ItemPartCodeType.Dim);
                                if (DimPartItem != null && StandradDimList.Count > 0)
                                {
                                    int CDim = StandradDimList.Find(item => item - 0.02 <= DimPartItem.XLength
                                    && DimPartItem.XLength <= item + 0.02);
                                    //该尺寸对应的导柱全量参数
                                    StandardGPSP ScrewItem = ParamsConfigData.StandardGPList.Find(item => item.Dimension == CDim);
                                    if (ScrewItem != null)
                                    {
                                        SingleItem SItem = new SingleItem();
                                        SItem.AssembleCenterPointX = DimPartItem.AVSplitCX;
                                        SItem.AVCustomerCX = DimPartItem.AVCustomerCX;
                                        refAVCPX = SItem.AssembleCenterPointX;
                                        SItem.TVCPX = DimPartItem.TVCPX;
                                        SItem.ItemNameType = DItemNameType.GuidePin;
                                        SItem.PeakY = DimAndTDInfoList.Select(item => item.LLine).Max(item => item.StartPoint.CustomerPoint.Y);
                                        SItem.NadirY = DimAndTDInfoList.Select(item => item.LLine).Min(item => item.EndPoint.CustomerPoint.Y);
                                        SItem.Dim = Math.Round(DimPartItem.XLength, 0);
                                        SItem.TD = ScrewItem.TD;
                                        //所有直径部位的集合
                                        List<CSinglePartItem> AllDimPartList = DimAndTDInfoList.FindAll(item =>
                                        item.ItemType == ItemPartCodeType.Dim);
                                        //托位部位
                                        CSinglePartItem TDPart = DimAndTDInfoList.Find(item => item.ItemType == ItemPartCodeType.TD
                                        && item.XLength == (double)SItem.TD);
                                        double RefCX = Math.Round(CTempGPList[i].CenterPoint.CustomerPoint.X, 1);
                                        double RefCLX = RefCX - 5;
                                        double RefCRX = RefCX + 5;
                                        if (!TPF)
                                        {
                                            for (int l = 0; l < TSGPLines.Count; l++)
                                            {
                                                double TTLineCX = Math.Round((TSGPLines[l].StartPoint.CustomerPoint.X + TSGPLines[l].EndPoint.CustomerPoint.X) / 2, 2);
                                                Boolean TCF = RefCLX <= TTLineCX && TTLineCX <= RefCRX;
                                                if (TCF)
                                                {
                                                    double TempTSXLength = Math.Round(TSGPLines[l].Length, 1);
                                                    //防止用户画图不标准
                                                    if (SItem.Dim - 0.5 <= TempTSXLength && TempTSXLength <= SItem.Dim + 0.5)
                                                        CDimTSLineList.Add(TSGPLines[l]);
                                                }
                                            }
                                        }
                                        //设置托位信息
                                        int TDBoardIndex = -1;
                                        List<CSinglePartItem> TDList = DimAndTDInfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD);
                                        {
                                            if (TDList.Count > 0)
                                            {
                                                //struct 
                                                List<CSinglePartItem> tempTDList = new List<CSinglePartItem>();
                                                tempTDList = TDList.FindAll(item => Math.Round(item.XLength, 0)
                                                == (double)SItem.TD);
                                                if (tempTDList.Count > 0)
                                                    TDList = tempTDList;
                                                //loose
                                                else
                                                {
                                                    tempTDList = TDList.FindAll(item => (double)SItem.TD - 1.1 <= Math.Round(item.XLength, 0)
                                                    && Math.Round(item.XLength, 0) <= (double)SItem.TD + 1.1);
                                                    if (tempTDList.Count > 0)
                                                        TDList = tempTDList;
                                                }
                                            }
                                        }
                                        if (TDList.Count > 0)
                                        {
                                            double LTDMaxY = TDList.Max(item => item.LLine.StartPoint.CustomerPoint.Y);
                                            double RTDMaxY = TDList.Max(item => item.RLine.StartPoint.CustomerPoint.Y);
                                            double LTDMinY = TDList.Min(item => item.LLine.EndPoint.CustomerPoint.Y);
                                            double TDRMinY = TDList.Min(item => item.RLine.EndPoint.CustomerPoint.Y);
                                            double TDMaxY = LTDMaxY > RTDMaxY ? LTDMaxY : RTDMaxY;
                                            double TDMinY = LTDMinY < TDRMinY ? LTDMinY : TDRMinY;
                                            double TDAgvY = (TDMaxY + TDMinY) / 2;
                                            TDBoardIndex = AboutDimAndTDBoardList.FindIndex(item => TDAgvY <= item.OverheadLine.StartPoint.CustomerPoint.Y &&
                                                    item.BottomLine.StartPoint.CustomerPoint.Y <= TDAgvY);

                                            //判断 导柱托位安装方式
                                            if (TDBoardIndex != -1)
                                            {
                                                SItem.TDBoard = AboutDimAndTDBoardList[TDBoardIndex];
                                                if (notTPF)
                                                {
                                                    UnloadMoldPosType TDWithaPosType = SItem.TDBoard.withaBoardPosType;
                                                    if (TDWithaPosType == UnloadMoldPosType.aBoardUp)
                                                        ShareItemBoardShipInfo.extraShipInfo.gpRevFlag = true;
                                                    if (TDWithaPosType == UnloadMoldPosType.aBoardDown)
                                                        ShareItemBoardShipInfo.extraShipInfo.gpRevFlag = false;
                                                }

                                                if (TDBoardIndex == 0)
                                                {
                                                    SItem.TDPosType = InBoardPosType.BoardUp;
                                                    //细水口 大水口的导柱 外轮廓特征可以利用Dim等长横线
                                                    if (!TPF)
                                                    {
                                                        if (CDimTSLineList.Count > 0)
                                                        {
                                                            //直径候选集 自下而上 找出第一根横线
                                                            MixedCAD_Line MinTSLine = CDimTSLineList.Find(TItem => TItem.StartPoint.CustomerPoint.Y
                                                            == CDimTSLineList.Min(item => item.StartPoint.CustomerPoint.Y));
                                                            //找出和这条横线相交的圆弧集合
                                                            List<MixedCAD_Arc> ConnArcList = GPCandiArcList.FindAll(item => CU.JudgeHorizontalLineArcConn(MinTSLine, item));
                                                            double? MinArcY = null;
                                                            if (ConnArcList.Count > 0)
                                                            {
                                                                double MinEPY = ConnArcList.Min(item => item.EndPoint.CustomerPoint.Y);
                                                                double MinSPY = ConnArcList.Min(item => item.StartPoint.CustomerPoint.Y);
                                                                MixedCAD_Arc LastEndPArc = ConnArcList.FindLast(item => item.EndPoint.CustomerPoint.Y == MinEPY);
                                                                MixedCAD_Arc LastStartPArc = ConnArcList.FindLast(item => item.StartPoint.CustomerPoint.Y == MinSPY);
                                                                MixedCAD_Point StartRPArcPoint = LastStartPArc.StartPoint.CustomerPoint.Y < LastStartPArc.EndPoint.CustomerPoint.Y ? LastStartPArc.StartPoint : LastStartPArc.EndPoint;
                                                                MixedCAD_Point EndRPArcPoint = LastEndPArc.StartPoint.CustomerPoint.Y < LastEndPArc.EndPoint.CustomerPoint.Y ? LastEndPArc.StartPoint : LastEndPArc.EndPoint;
                                                                MinArcY = StartRPArcPoint.CustomerPoint.Y < EndRPArcPoint.CustomerPoint.Y ? StartRPArcPoint.CustomerPoint.Y : EndRPArcPoint.CustomerPoint.Y;
                                                            }
                                                            if (MinArcY != null)
                                                            {
                                                                SItem.PeakY = SItem.TDBoard.OverheadLine.StartPoint.CustomerPoint.Y;
                                                                SItem.NadirY = (double)MinArcY;
                                                                //导柱长度
                                                                if (SItem.PeakY != null && SItem.NadirY != null)
                                                                    SItem.RealH = Convert.ToInt32(Math.Round((double)SItem.PeakY - (double)SItem.NadirY, 0));
                                                                SItem.TheoryH = CU.GPTheoryLRepRule(SItem.RealH);
                                                            }
                                                        }
                                                        //没Dim横线
                                                        else
                                                        {
                                                            //find Dim Arc most 
                                                            if (GPCandiArcList.Count > 0)
                                                            {
                                                                List<double> arcSYList = GPCandiArcList.Select(item => item.StartPoint.CustomerPoint.Y).ToList();
                                                                List<double> arcEYList = GPCandiArcList.Select(item => item.EndPoint.CustomerPoint.Y).ToList();
                                                                List<double> tempArcPYList = new List<double>();
                                                                tempArcPYList.AddRange(arcSYList);
                                                                tempArcPYList.AddRange(arcEYList);
                                                                if (tempArcPYList.Count > 0)
                                                                    SItem.NadirY = tempArcPYList.Min();
                                                            }
                                                            List<CSinglePartItem> noTDimTDList = GPItemVList.FindAll(item => item.ItemType == ItemPartCodeType.TD);
                                                            double? maxY = null;
                                                            if (noTDimTDList.Count > 0)
                                                            {
                                                                double L = noTDimTDList.Max(item => item.LLine.StartPoint.CustomerPoint.Y);
                                                                double R = noTDimTDList.Max(item => item.RLine.StartPoint.CustomerPoint.Y);
                                                                maxY = L > R ? L : R;
                                                            }
                                                            if (maxY != null)
                                                                SItem.PeakY = (double)maxY;

                                                            if (SItem.PeakY != null && SItem.NadirY != null)
                                                            {
                                                                SItem.RealH = Convert.ToInt32(Math.Round((double)SItem.PeakY - (double)SItem.NadirY, 0));
                                                                SItem.TheoryH = CU.GPTheoryLRepRule(SItem.RealH);
                                                            }
                                                        }
                                                    }
                                                    //简化型
                                                    else
                                                    {
                                                        SItem.PeakY = SItem.TDBoard.OverheadLine.StartPoint.CustomerPoint.Y;
                                                        List<CSinglePartItem> TPgpDimList = GPItemVList.FindAll(item => item.ItemType == ItemPartCodeType.Dim).ToList();
                                                        if (TPgpDimList.Count > 0)
                                                        {
                                                            MixedCAD_Line GPMinLLine = null;
                                                            MixedCAD_Line GPMinRLine = null;

                                                            List<CSinglePartItem> afterFilterDimList = new List<CSinglePartItem>();
                                                            for(int k = 0; k < TPgpDimList.Count(); k++)
                                                            {
                                                                bool F = ComputedUtils.LRCSingleLengthSame(TPgpDimList[k]);
                                                                if (F)
                                                                    afterFilterDimList.Add(TPgpDimList[k]);
                                                            }
                                                            if(afterFilterDimList.Count > 0)
                                                            {

                                                                List<MixedCAD_Line> GPDimLList = afterFilterDimList.Select(item => item.LLine).ToList();
                                                                List<MixedCAD_Line> GPDimRList = afterFilterDimList.Select(item => item.RLine).ToList();

                                                                if (GPDimLList.Count > 0)
                                                                {
                                                                    double MingpDimLY = GPDimLList.Min(item => item.EndPoint.CustomerPoint.Y);
                                                                    GPMinLLine = GPDimLList.Find(item => item.EndPoint.CustomerPoint.Y == MingpDimLY);
                                                                }
                                                                if (GPDimRList.Count > 0)
                                                                {
                                                                    double MingpDimRY = GPDimRList.Min(item => item.EndPoint.CustomerPoint.Y);
                                                                    GPMinRLine = GPDimRList.Find(item => item.EndPoint.CustomerPoint.Y == MingpDimRY);
                                                                }
                                                                if (GPMinLLine != null && GPMinRLine != null)
                                                                {
                                                                    MixedCAD_Arc ConnLArc = GPCandiArcList.Find(item => CU.JudgeVerticalLineEndPointArcConn(GPMinLLine, item));
                                                                    MixedCAD_Arc ConnRArc = GPCandiArcList.Find(item => CU.JudgeVerticalLineEndPointArcConn(GPMinRLine, item));
                                                                    if (ConnLArc != null || ConnRArc != null)
                                                                    {
                                                                        double? LArcY = null;
                                                                        double? RArcY = null;
                                                                        double? MinArcY = null;
                                                                        if (ConnLArc != null)
                                                                            LArcY = ConnLArc.EndPoint.CustomerPoint.Y;
                                                                        if (ConnRArc != null)
                                                                            RArcY = ConnRArc.EndPoint.CustomerPoint.Y;
                                                                        if (LArcY != null && RArcY != null)
                                                                            MinArcY = LArcY < RArcY ? LArcY : RArcY;
                                                                        else
                                                                        {
                                                                            if (LArcY != null)
                                                                                MinArcY = LArcY;
                                                                            if (RArcY != null)
                                                                                MinArcY = RArcY;
                                                                        }
                                                                        if (MinArcY != null)
                                                                            SItem.NadirY = (double)MinArcY;
                                                                        if (SItem.PeakY != null && SItem.NadirY != null)
                                                                            SItem.RealH = Convert.ToInt32(Math.Round((double)SItem.PeakY - (double)SItem.NadirY, 0));
                                                                        SItem.TheoryH = CU.GPTheoryLRepRule(SItem.RealH);
                                                                    }
                                                                    else
                                                                    {
                                                                        SItem.RealH = Convert.ToInt32(Math.Round((double)SItem.PeakY - (double)SItem.NadirY, 0));
                                                                        SItem.TheoryH = CU.GPTheoryLRepRule(SItem.RealH);
                                                                    }

                                                                }
                                                            }
                                                            
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    SItem.TDPosType = InBoardPosType.BoardDown;
                                                    //细水口 大水口的导柱 外轮廓特征可以利用Dim等长横线
                                                    if (!TPF)
                                                    {
                                                        //有Dim横线
                                                        if (CDimTSLineList.Count > 0)
                                                        {
                                                            //直径候选集 自上而下 找出第一根横线
                                                            MixedCAD_Line MaxTSLine = CDimTSLineList.Find(TItem => TItem.StartPoint.CustomerPoint.Y
                                                            == CDimTSLineList.Max(item => item.StartPoint.CustomerPoint.Y));
                                                            //找出和这条横线相交的圆弧集合
                                                            List<MixedCAD_Arc> ConnArcList = GPCandiArcList.FindAll(item => CU.JudgeArcCenterInLine(MaxTSLine, item));
                                                            double? MaxArcY = null;
                                                            //有 最顶上的横线相邻特征圆弧
                                                            if (ConnArcList.Count > 0)
                                                            {
                                                                double MaxEPY = ConnArcList.Max(item => item.EndPoint.CustomerPoint.Y);
                                                                double MaxSPY = ConnArcList.Max(item => item.StartPoint.CustomerPoint.Y);
                                                                MixedCAD_Arc LastEndPArc = ConnArcList.FindLast(item => item.EndPoint.CustomerPoint.Y == MaxEPY);
                                                                MixedCAD_Arc LastStartPArc = ConnArcList.FindLast(item => item.StartPoint.CustomerPoint.Y == MaxSPY);
                                                                MixedCAD_Point StartRPArcPoint = LastStartPArc.StartPoint.CustomerPoint.Y > LastStartPArc.EndPoint.CustomerPoint.Y ? LastStartPArc.StartPoint : LastStartPArc.EndPoint;
                                                                MixedCAD_Point EndRPArcPoint = LastEndPArc.StartPoint.CustomerPoint.Y > LastEndPArc.EndPoint.CustomerPoint.Y ? LastEndPArc.StartPoint : LastEndPArc.EndPoint;
                                                                MaxArcY = StartRPArcPoint.CustomerPoint.Y > EndRPArcPoint.CustomerPoint.Y ? StartRPArcPoint.CustomerPoint.Y : EndRPArcPoint.CustomerPoint.Y;
                                                            }
                                                            //无 根据位置去找
                                                            else
                                                            {
                                                                if (GPCandiArcList.Count > 0)
                                                                {
                                                                    double LroundX = (double)AVTDRealCenterX - SItem.Dim / 2;
                                                                    double RroundX = (double)AVTDRealCenterX + SItem.Dim / 2;
                                                                    GPCandiArcList = GPCandiArcList.FindAll(item => LroundX <= item.CenterPoint.CustomerPoint.X
                                                                    && item.CenterPoint.CustomerPoint.X <= RroundX);
                                                                    if (GPCandiArcList.Count > 0)
                                                                    {

                                                                        double MaxCirY = GPCandiArcList.Select(item => item.CenterPoint.CustomerPoint.Y).ToList().Max();
                                                                        MixedCAD_Arc targetRefCir = GPCandiArcList.Find(item => item.CenterPoint.CustomerPoint.Y == MaxCirY);
                                                                        MixedCAD_Point targetArcPoint = targetRefCir.StartPoint.CustomerPoint.Y > targetRefCir.EndPoint.CustomerPoint.Y ? targetRefCir.StartPoint : targetRefCir.EndPoint;
                                                                        MaxArcY = targetArcPoint.CustomerPoint.Y;
                                                                    }
                                                                }
                                                            }
                                                            if (MaxArcY != null)
                                                            {
                                                                //圆弧点集合里面最高点
                                                                SItem.PeakY = (double)MaxArcY;
                                                                SItem.NadirY = SItem.TDBoard.BottomLine.StartPoint.CustomerPoint.Y;
                                                            }
                                                            if (SItem.PeakY != null && SItem.NadirY != null)
                                                                //导柱长度
                                                                SItem.RealH = Convert.ToInt32(Math.Round((double)SItem.PeakY - (double)SItem.NadirY, 0));
                                                            SItem.TheoryH = CU.GPTheoryLRepRule(SItem.RealH);
                                                        }
                                                        //没Dim横线
                                                        else
                                                        {
                                                            //find Dim Arc most 
                                                            if (GPCandiArcList.Count > 0)
                                                            {
                                                                List<double> arcSYList = GPCandiArcList.Select(item => item.StartPoint.CustomerPoint.Y).ToList();
                                                                List<double> arcEYList = GPCandiArcList.Select(item => item.EndPoint.CustomerPoint.Y).ToList();
                                                                List<double> tempArcPYList = new List<double>();
                                                                tempArcPYList.AddRange(arcSYList);
                                                                tempArcPYList.AddRange(arcEYList);
                                                                if (tempArcPYList.Count > 0)
                                                                    SItem.PeakY = tempArcPYList.Max();
                                                            }
                                                            List<CSinglePartItem> noTDimTDList = GPItemVList.FindAll(item => item.ItemType
                                                            == ItemPartCodeType.TD);
                                                            double? minY = null;
                                                            if (noTDimTDList.Count > 0)
                                                            {
                                                                double L = noTDimTDList.Min(item => item.LLine.EndPoint.CustomerPoint.Y);
                                                                double R = noTDimTDList.Min(item => item.RLine.EndPoint.CustomerPoint.Y);
                                                                minY = L < R ? L : R;
                                                            }
                                                            if (minY != null)
                                                                SItem.NadirY = (double)minY;

                                                            if (SItem.PeakY != null && SItem.NadirY != null)
                                                                //导柱长度
                                                                SItem.RealH = Convert.ToInt32(Math.Round((double)SItem.PeakY - (double)SItem.NadirY, 0));
                                                            SItem.TheoryH = CU.GPTheoryLRepRule(SItem.RealH);
                                                        }
                                                    }

                                                }
                                            }
                                        }

                                        //整个导柱所在板
                                        int BeginBIndex = AssemblyShareData.ASectionList.FindLastIndex(item => Math.Round(item.OverheadLine.StartPoint.CustomerPoint.Y) >= 
                                        Math.Round((double)SItem.PeakY, 0));
                                        int EndBIndex = AssemblyShareData.ASectionList.FindIndex(item => Math.Round(item.BottomLine.StartPoint.CustomerPoint.Y) <= 
                                        Math.Round((double)SItem.NadirY, 0));
                                        if (BeginBIndex != -1 && EndBIndex != -1)
                                        {
                                            int BIndex = BeginBIndex < EndBIndex ? BeginBIndex : EndBIndex;
                                            int EIndex = BeginBIndex > EndBIndex ? BeginBIndex : EndBIndex;
                                            GPScopeBoardList = AssemblyShareData.ASectionList.GetRange(BIndex, EIndex - BIndex + 1);
                                            string TDUID = SItem.TDBoard.BoardUID;
                                            double SPLH = (double)SItem.PeakY - (double)SItem.NadirY;
                                            double allGPScopeBH = 0;
                                            GPScopeBoardList.ForEach(item => allGPScopeBH += item.PlateThick);
                                            allGPScopeBH = Math.Round(allGPScopeBH, 0);
                                            SPLH = Math.Round(SPLH, 0);
                                            if(allGPScopeBH != SPLH)
                                            {
                                                int tdBIndex = GPScopeBoardList.FindIndex(item => item.BoardUID.Equals(TDUID));
                                                if(tdBIndex != -1)
                                                {
                                                    List<BoardSectionItem> LBList = (List<BoardSectionItem>)ConvertUtils.DeepCopy(GPScopeBoardList);
                                                    double difGPScopeH = 0;
                                                    if (tdBIndex == 0)
                                                    {
                                                        SItem.blindInfo.BlindBoardUID = LBList[LBList.Count - 1].BoardUID;
                                                        LBList.RemoveAt(LBList.Count - 1);
                                                        if(LBList.Count > 0)
                                                            LBList.ForEach(item => difGPScopeH += item.PlateThick);
                                                        SItem.blindInfo.BlindInBoardType = InBoardType.Up;
                                                        
                                                    }
                                                    if(tdBIndex == GPScopeBoardList.Count - 1)
                                                    {
                                                        SItem.blindInfo.BlindBoardUID = LBList[0].BoardUID;
                                                        LBList.RemoveAt(0);
                                                        if (LBList.Count > 0)
                                                            LBList.ForEach(item => difGPScopeH += item.PlateThick);
                                                        SItem.blindInfo.BlindInBoardType = InBoardType.Down;
                                                    }
                                                    double itemBlindH = SPLH - difGPScopeH;
                                                    SItem.blindInfo.H = itemBlindH;
                                                }
                                            }
                                        }

                                        //导套托位
                                        if (BushTDValueList.Count > 0)
                                        {
                                            double nearBushTDDif = BushTDValueList.Max(item => Math.Abs(item - ScrewItem.BushTD));
                                            double bestbushTDValue = BushTDValueList.Find(item => Math.Abs(item - ScrewItem.BushTD) == nearBushTDDif);
                                            bestbushTDValue = Math.Round(bestbushTDValue, 0);
                                            SItem.BushTD = (int)bestbushTDValue;
                                        }

                                        if (BushSizeValueList.Count > 0)
                                        {
                                            double nearBushSizeDif = BushSizeValueList.Min(item => Math.Abs(item - ScrewItem.BushSize));
                                            SItem.BushSize = (int)BushSizeValueList.Find(item => Math.Abs(item - ScrewItem.BushSize) == nearBushSizeDif);
                                        }
                                        double TH = 0;
                                        List<CSinglePartItem> CTDList = CTempGPList[i].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD);
                                        //托位深度
                                        if (CTDList.Count > 0)
                                            TH = CTDList.Select(item => item.YLength).Distinct().Min();
                                        SItem.TH = Convert.ToDecimal(TH);
                                        SItem.MatchScrewHole = CTempGPList[i].MatchScrewHole;
                                        SItem.RelScrewHoleList = CTempGPList[i].RelScrewHoleList;
                                        SItem.ItemNum = SItem.RelScrewHoleList.Count;
                                        RefHoleCenterSplitInfo SInfo = TranRefCHoleData(SItem.ItemNameType, SItem.RelScrewHoleList);
                                        SItem.HSplitInfo = SInfo;
                                        if (SItem.TDBoard.BoardUID != null)
                                            if (SItem.TDBoard.BoardCode.Equals("spBoard"))
                                                ShareItemBoardShipInfo.extraShipInfo.gpOverSpFlag = true;

                                        List<SingleItem> BushItemList = new List<SingleItem>();
                                        //接着提取导柱上面的导套零件数据
                                        //导套所在板区间范围
                                        double DimLX = (double)AVTDRealCenterX - SItem.Dim / 2;
                                        double DimRX = (double)AVTDRealCenterX + SItem.Dim / 2;
                                        double BushLX = (double)AVTDRealCenterX - SItem.BushSize / 2;
                                        double BushRX = (double)AVTDRealCenterX + SItem.BushSize / 2;
                                        //区域 导套出现的板UID
                                        List<BoardAboutBushInfo> AboutBushUIDList = new List<BoardAboutBushInfo>();
                                        //收集信息
                                        if (MergeBushTDInfoList.Count > 0)
                                        {
                                            for (int tdi = 0; tdi < MergeBushTDInfoList.Count; tdi++)
                                            {
                                                BoardAboutBushInfo BoardBushInfo = new BoardAboutBushInfo();
                                                BoardBushInfo.BoardUID = MergeBushTDInfoList[tdi].BushTDBoard.BoardUID;
                                                BoardBushInfo.BushType = BushBoardType.B;
                                                AboutBushUIDList.Add(BoardBushInfo);
                                            }
                                        }
                                        if (BushSizeBoardList.Count > 0)
                                        {
                                            for (int bsi = 0; bsi < BushSizeBoardList.Count; bsi++)
                                            {
                                                BoardAboutBushInfo BoardBushInfo = new BoardAboutBushInfo();
                                                BoardBushInfo.BoardUID = BushSizeBoardList[bsi].BoardUID;
                                                BoardBushInfo.BushType = BushBoardType.A;
                                                AboutBushUIDList.Add(BoardBushInfo);
                                            }
                                        }
                                        AboutBushUIDList = AboutBushUIDList.Distinct().ToList();
                                        if (AboutBushUIDList.Count > 0)
                                        {
                                            List<BoardSectionItem> AboutBushBList = AboutBushBoardList.FindAll(item =>
                                            AboutBushUIDList.Select(UIDItem => UIDItem.BoardUID).Contains(item.BoardUID));
                                            if (AboutBushBList.Count > 0 && AArcList.Count > 0)
                                            {
                                                double BushTY = AboutBushBList.Max(item => item.OverheadLine.StartPoint.CustomerPoint.Y);
                                                double BushBY = AboutBushBList.Min(item => item.BottomLine.StartPoint.CustomerPoint.Y);
                                                AboutBushBList = AboutBushBList.OrderBy(item => item.plateLineNo).ToList();
                                                //以板UID为KEY 各板的圆弧特征 字典(收集)
                                                Dictionary<string, List<MixedCAD_Arc>> AllContainsArcDic = new Dictionary<string, List<MixedCAD_Arc>>();
                                                for (int k = 0; k < AboutBushBList.Count; k++)
                                                {
                                                    double BushBoardMaxY = AboutBushBList[k].OverheadLine.StartPoint.CustomerPoint.Y;
                                                    double BushBoardMinY = AboutBushBList[k].BottomLine.StartPoint.CustomerPoint.Y;
                                                    //导套圆弧集合
                                                    List<MixedCAD_Arc> TempBushCArcList = new List<MixedCAD_Arc>(AArcList);
                                                    TempBushCArcList = TempBushCArcList.FindAll(item =>
                                                    BushBoardMinY < item.CenterPoint.CustomerPoint.Y && item.CenterPoint.CustomerPoint.Y < BushBoardMaxY);

                                                    if (TempBushCArcList.Count > 0)
                                                        TempBushCArcList = TempBushCArcList.FindAll(item =>
                                                        CU.JudgeArcConformDimbush(item, BushTY, BushBY, DimLX, DimRX, BushLX, BushRX));

                                                    TempBushCArcList = TempBushCArcList.FindAll(item => item.Radius > 2.5);
                                                    //设置圆弧朝向 用于判断导套特征圆弧 数量
                                                    CU.SetArcDirListBySEPoint(TempBushCArcList);
                                                    if (TempBushCArcList.Count > 0)
                                                    {
                                                        string UID = AboutBushBList[k].BoardUID;
                                                        if (AllContainsArcDic.ContainsKey(UID))
                                                            AllContainsArcDic[UID].AddRange(TempBushCArcList);
                                                        else
                                                            AllContainsArcDic.Add(UID, new List<MixedCAD_Arc>(TempBushCArcList));
                                                    }
                                                }
                                                //导套区域 客图有画 圆弧 的板UID
                                                List<string> HasArcBoardUIDKeys = AllContainsArcDic.Keys.ToList();
                                                //导套区域 客图没画 圆弧 的板UID 
                                                List<string> NoHasArcBoardUIDKeys = new List<string>();
                                                if (AboutBushUIDList.Count > 0 && HasArcBoardUIDKeys.Count > 0)
                                                {
                                                    List<string> allBushBoardUIDList = AboutBushUIDList.Select(item => item.BoardUID).ToList();
                                                    NoHasArcBoardUIDKeys = allBushBoardUIDList.Where(item => !HasArcBoardUIDKeys.Contains(item)).ToList();
                                                }

                                                //有 与套 相关的圆弧
                                                if (HasArcBoardUIDKeys.Count > 0)
                                                {
                                                    //连套索引信息(一组(4)横跨两块板)
                                                    List<ContinueBushIInfo> ContinueIndexesList = new List<ContinueBushIInfo>();
                                                    if (HasArcBoardUIDKeys.Count > 1)
                                                    {
                                                        for (int k = 0; k < HasArcBoardUIDKeys.Count - 1; k++)
                                                        {
                                                            int l = k + 1;
                                                            string KUID = HasArcBoardUIDKeys[k];
                                                            string IUID = HasArcBoardUIDKeys[l];
                                                            List<MixedCAD_Arc> KIUIDArcList = new List<MixedCAD_Arc>();
                                                            if (AllContainsArcDic.ContainsKey(KUID) && AllContainsArcDic.ContainsKey(IUID))
                                                            {
                                                                List<MixedCAD_Arc> KUIDArcList = AllContainsArcDic[KUID];
                                                                List<MixedCAD_Arc> IUIDArcList = AllContainsArcDic[IUID];
                                                                KIUIDArcList.AddRange(KUIDArcList);
                                                                KIUIDArcList.AddRange(IUIDArcList);
                                                                //判断导套圆弧是否跨板(一组板上没有四个方向的特征圆弧 默认跨板)
                                                                Boolean StraddlePlateF = CU.OneBoardNoBArcFourDic(KIUIDArcList);
                                                                //跨板 记录连套索引信息
                                                                if (StraddlePlateF)
                                                                {
                                                                    ContinueBushIInfo TCBushIndexInfo = new ContinueBushIInfo();
                                                                    TCBushIndexInfo.BeginBoardUID = KUID;
                                                                    TCBushIndexInfo.EndBoardUID = IUID;
                                                                    ContinueIndexesList.Add(TCBushIndexInfo);
                                                                }
                                                            }
                                                        }
                                                    }
                                                    //处理连套 Add Bush
                                                    if (ContinueIndexesList.Count > 0)
                                                    {
                                                        for (int k = 0; k < ContinueIndexesList.Count; k++)
                                                        {
                                                            List<string> BEUIDList = new List<string>();
                                                            string BUID = ContinueIndexesList[k].BeginBoardUID;
                                                            string EUID = ContinueIndexesList[k].EndBoardUID;
                                                            BEUIDList.Add(BUID);
                                                            BEUIDList.Add(EUID);
                                                            List<MixedCAD_Arc> BUIDArcList = AllContainsArcDic[BUID];
                                                            List<MixedCAD_Arc> EUIDArcList = AllContainsArcDic[EUID];
                                                            List<MixedCAD_Arc> BEUIDArcList = new List<MixedCAD_Arc>();
                                                            BEUIDArcList.AddRange(BUIDArcList);
                                                            BEUIDArcList.AddRange(EUIDArcList);
                                                            double ABBushMaxY = BEUIDArcList.Max(item => item.StartPoint.CustomerPoint.Y);
                                                            double ABBushMinY = BEUIDArcList.Min(item => item.EndPoint.CustomerPoint.Y);
                                                            int BushTDIndex = MergeBushTDInfoList.FindIndex(item => BEUIDList.Contains(item.BushTDBoard.BoardUID));
                                                            SingleItem BushItem = new SingleItem();
                                                            if (BushTDIndex == -1)
                                                            {
                                                                BushItem.ItemCode = "GuideABush";
                                                                BushItem.ItemNameType = DItemNameType.GuideABush;
                                                            }
                                                            else
                                                            {
                                                                BushItem.BushTDBoard = MergeBushTDInfoList[BushTDIndex].BushTDBoard;
                                                                BushItem.BushTDPosType = MergeBushTDInfoList[BushTDIndex].BushTDPosType;
                                                                BushItem.ItemCode = "GuideBBush";
                                                                BushItem.ItemNameType = DItemNameType.GuideBBush;
                                                            }
                                                            BushItem.AssembleCenterPointX = (double)refAVCPX;
                                                            BushItem.PeakY = ABBushMaxY;
                                                            BushItem.NadirY = ABBushMinY;
                                                            BushItem.RealH = Convert.ToInt32(Math.Round(ABBushMaxY - ABBushMinY, 0));
                                                            BushItem.TheoryH = CU.BushCustomerLTranToTheoryL(BushItem.RealH);
                                                            BushItem.Dim = SItem.Dim;
                                                            Boolean BBushF = BushItem.ItemCode.Contains("BBush");
                                                            if (BBushF)
                                                            {
                                                                SetSPGPBBushTH(MergeBushTDInfoList, BushItem);
                                                                if (BushItem.BushBoardList.Count > 0)
                                                                {
                                                                    List<string> bbushBCodeList = BushItem.BushBoardList.Select(item => item.BoardUID).ToList();
                                                                    string targetUID = BushItem.BushTDBoard.BoardUID;
                                                                    if (targetUID != null)
                                                                    {
                                                                        Boolean BF = bbushBCodeList.Contains(targetUID);
                                                                        if (BF)
                                                                        {
                                                                            int targetUIDIndex = BushItem.BushBoardList.FindIndex(item => item.BoardUID.Equals(targetUID));
                                                                            if (targetUIDIndex != -1)
                                                                                BushItem.BushBoardList.RemoveAt(targetUIDIndex);
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                            BushItem.BushTD = SItem.BushTD;
                                                            BushItem.BushSize = SItem.BushSize;
                                                            CU.BushTransToProcessData("GPBush",BushItem);
                                                            BushItem.RelScrewHoleList = SItem.RelScrewHoleList;
                                                            BushItem.ItemNum = BushItem.RelScrewHoleList.Count;
                                                            BushItemList.Add(BushItem);
                                                        }
                                                    }
                                                    //有画圆弧 但无连套
                                                    List<BoardSectionItem> HasArcButNoConnBList = new List<BoardSectionItem>();
                                                    //先排除连套板干扰 剩下的每块板都去推算导套
                                                    if (ContinueIndexesList.Count > 0)
                                                    {
                                                        List<string> AllCBEUIDList = new List<string>();
                                                        List<string> AllCBUIDList = ContinueIndexesList.Select(item => item.BeginBoardUID).ToList();
                                                        List<string> AllCEUIDList = ContinueIndexesList.Select(item => item.EndBoardUID).ToList();
                                                        AllCBEUIDList.AddRange(AllCBUIDList);
                                                        AllCBEUIDList.AddRange(AllCEUIDList);
                                                        List<string> NOAllCEUIDList = AboutBushUIDList.Select(item => item.BoardUID).ToList().FindAll(item => !AllCBEUIDList.Contains(item));
                                                        HasArcButNoConnBList = AboutBushBList.FindAll(item => HasArcBoardUIDKeys.Contains(item.BoardUID));
                                                        HasArcButNoConnBList = HasArcButNoConnBList.FindAll(item => NOAllCEUIDList.Contains(item.BoardUID));
                                                    }
                                                    else
                                                        HasArcButNoConnBList = AboutBushBList.FindAll(item => HasArcBoardUIDKeys.Contains(item.BoardUID));

                                                    //处理有圆弧 非连套 Add Bush
                                                    if (HasArcButNoConnBList.Count > 0)
                                                    {
                                                        for (int k = 0; k < HasArcButNoConnBList.Count; k++)
                                                        {
                                                            string BUID = HasArcButNoConnBList[k].BoardUID;
                                                            if (AllContainsArcDic.ContainsKey(BUID))
                                                            {
                                                                List<MixedCAD_Arc> OBBushArcList = AllContainsArcDic[BUID];
                                                                SingleItem BushItem = new SingleItem();
                                                                int BushTDIndex = MergeBushTDInfoList.FindIndex(item => HasArcButNoConnBList[k].BoardUID.Equals(item.BushTDBoard.BoardUID));
                                                                if (BushTDIndex == -1)
                                                                {
                                                                    BushItem.ItemCode = "GuideABush";
                                                                    BushItem.ItemNameType = DItemNameType.GuideABush;
                                                                }
                                                                else
                                                                {
                                                                    BushItem.BushTDBoard = MergeBushTDInfoList[BushTDIndex].BushTDBoard;
                                                                    BushItem.BushTDPosType = MergeBushTDInfoList[BushTDIndex].BushTDPosType;
                                                                    BushItem.ItemCode = "GuideBBush";
                                                                    BushItem.ItemNameType = DItemNameType.GuideBBush;
                                                                }
                                                                MixedCAD_Arc TLArc = OBBushArcList.Find(item => item.Dir == AngleDir.TL);
                                                                MixedCAD_Arc TRArc = OBBushArcList.Find(item => item.Dir == AngleDir.TR);
                                                                MixedCAD_Arc BLArc = OBBushArcList.Find(item => item.Dir == AngleDir.BL);
                                                                MixedCAD_Arc BRArc = OBBushArcList.Find(item => item.Dir == AngleDir.BR);
                                                                double? BushArcMaxY = null;
                                                                double? BushArcMinY = null;
                                                                Boolean TopPortF = TLArc != null && TRArc != null;
                                                                Boolean BootomPortF = BLArc != null && BRArc != null;
                                                                if (TopPortF)
                                                                    BushArcMaxY = TLArc.StartPoint.CustomerPoint.Y > TRArc.StartPoint.CustomerPoint.Y ? TLArc.StartPoint.CustomerPoint.Y : TRArc.StartPoint.CustomerPoint.Y;
                                                                if (BootomPortF)
                                                                    BushArcMinY = BLArc.EndPoint.CustomerPoint.Y < BRArc.EndPoint.CustomerPoint.Y ? BLArc.EndPoint.CustomerPoint.Y : BRArc.EndPoint.CustomerPoint.Y;
                                                                if (TopPortF && BootomPortF)
                                                                {
                                                                    BushItem.RealH = Convert.ToInt32(Math.Round((double)BushArcMaxY - (double)BushArcMinY, 0));
                                                                    BushItem.PeakY = (double)BushArcMaxY;
                                                                    BushItem.NadirY = (double)BushArcMinY;
                                                                    BushItem.BushBoardList.Add(HasArcButNoConnBList[k]);
                                                                }
                                                                else
                                                                {
                                                                    if (TopPortF || BootomPortF)
                                                                    {
                                                                        if (TopPortF)
                                                                        {
                                                                            double BY = HasArcButNoConnBList[k].BottomLine.StartPoint.CustomerPoint.Y;
                                                                            BushItem.RealH = (int)(BushArcMaxY - BY);
                                                                            BushItem.PeakY = BushArcMaxY;
                                                                            BushItem.NadirY = BY;
                                                                        }
                                                                        if (BootomPortF)
                                                                        {
                                                                            double TY = HasArcButNoConnBList[k].OverheadLine.StartPoint.CustomerPoint.Y;
                                                                            BushItem.RealH = (int)(TY - BushArcMinY);
                                                                            BushItem.PeakY = TY;
                                                                            BushItem.NadirY = BushArcMinY;
                                                                        }
                                                                        BushItem.BushBoardList.Add(HasArcButNoConnBList[k]);
                                                                    }
                                                                    //两端都没圆弧 就认为这个需要加到没画套的板UID中
                                                                    else
                                                                        NoHasArcBoardUIDKeys.Add(HasArcButNoConnBList[k].BoardUID);
                                                                }
                                                                Boolean BBushF = BushItem.ItemCode.Contains("BBush");
                                                                if (BBushF)
                                                                {
                                                                    SetSPGPBBushTH(MergeBushTDInfoList, BushItem);
                                                                    if (BushItem.BushBoardList.Count > 0)
                                                                    {
                                                                        List<string> bbushBCodeList = BushItem.BushBoardList.Select(item => item.BoardUID).ToList();
                                                                        string targetUID = BushItem.BushTDBoard.BoardUID;
                                                                        if (targetUID != null)
                                                                        {
                                                                            Boolean BF = bbushBCodeList.Contains(targetUID);
                                                                            if (BF)
                                                                            {
                                                                                int targetUIDIndex = BushItem.BushBoardList.FindIndex(item => item.BoardUID.Equals(targetUID));
                                                                                if (targetUIDIndex != -1)
                                                                                    BushItem.BushBoardList.RemoveAt(targetUIDIndex);
                                                                            }
                                                                        }
                                                                    }
                                                                }

                                                                BushItem.AssembleCenterPointX = (double)refAVCPX;
                                                                BushItem.TheoryH = CU.BushCustomerLTranToTheoryL(BushItem.RealH);
                                                                BushItem.Dim = SItem.Dim;
                                                                BushItem.BushTD = SItem.BushTD;
                                                                BushItem.BushSize = SItem.BushSize;
                                                                CU.BushTransToProcessData("GPBush",BushItem);
                                                                BushItem.RelScrewHoleList = SItem.RelScrewHoleList;
                                                                BushItem.HSplitInfo.SplitInfoList = SItem.HSplitInfo.SplitInfoList;
                                                                BushItem.ItemNum = BushItem.RelScrewHoleList.Count;
                                                                BushItemList.Add(BushItem);
                                                            }
                                                        }
                                                    }
                                                }

                                                //处理 检查没圆弧的套直径板 没画套相关的圆弧 导套穿过多少板 就算多少套 Add Bush
                                                if (NoHasArcBoardUIDKeys.Count > 0)
                                                {
                                                    List<BoardSectionItem> NDList = AboutBushBList.FindAll(item => NoHasArcBoardUIDKeys.Contains(item.BoardUID));
                                                    for (int bsi = 0; bsi < NDList.Count; bsi++)
                                                    {
                                                        SingleItem BushItem = new SingleItem();
                                                        Boolean F = BushTDBoardUIDList.Contains(NDList[bsi].BoardUID);
                                                        if (F)
                                                        {
                                                            BushItem.ItemCode = "GuideBBush";
                                                            BushItem.ItemNameType = DItemNameType.GuideBBush;
                                                        }
                                                        else
                                                        {
                                                            BushItem.ItemCode = "GuideABush";
                                                            BushItem.ItemNameType = DItemNameType.GuideABush;
                                                        }
                                                        BushItem.AssembleCenterPointX = (double)refAVCPX;
                                                        BushItem.PeakY = NDList[bsi].OverheadLine.StartPoint.CustomerPoint.Y;
                                                        BushItem.NadirY = NDList[bsi].BottomLine.StartPoint.CustomerPoint.Y;
                                                        BushItem.BushBoardList.Add(NDList[bsi]);
                                                        BushItem.RealH = (int)NDList[bsi].PlateThick;
                                                        BushItem.TheoryH = CU.BushCustomerLTranToTheoryL(BushItem.RealH);
                                                        BushItem.Dim = SItem.Dim;
                                                        Boolean BBushF = BushItem.ItemCode.Contains("BBush");
                                                        if (BBushF)
                                                        {
                                                            SetSPGPBBushTH(MergeBushTDInfoList, BushItem);
                                                            if (BushItem.BushBoardList.Count > 0)
                                                            {
                                                                List<string> bbushBCodeList = BushItem.BushBoardList.Select(item => item.BoardUID).ToList();
                                                                string targetUID = BushItem.BushTDBoard.BoardUID;
                                                                if (targetUID != null)
                                                                {
                                                                    Boolean BF = bbushBCodeList.Contains(targetUID);
                                                                    if (BF)
                                                                    {
                                                                        int targetUIDIndex = BushItem.BushBoardList.FindIndex(item => item.BoardUID.Equals(targetUID));
                                                                        if (targetUIDIndex != -1)
                                                                            BushItem.BushBoardList.RemoveAt(targetUIDIndex);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        BushItem.BushTD = SItem.BushTD;
                                                        BushItem.BushSize = SItem.BushSize;
                                                        BushItem.RelScrewHoleList = SItem.RelScrewHoleList;
                                                        BushItem.ItemNum = BushItem.RelScrewHoleList.Count;
                                                        CU.BushTransToProcessData("GPBush",BushItem);
                                                        BushItemList.Add(BushItem);
                                                    }
                                                }
                                            }
                                        }

                                        if (BushItemList.Count > 0)
                                            ShareItemData.ItemList.AddRange(BushItemList);

                                        if (GPScopeBoardList.Count > 0)
                                        {
                                            //可能 有 避空区域 = GP Board - GP TD Board - 套 
                                            List<BoardSectionItem> maybeBKBoardList = (List<BoardSectionItem>)ConvertUtils.DeepCopyObject(GPScopeBoardList);
                                            string TDBUID = SItem.TDBoard.BoardUID;
                                            if (TDBUID != null)
                                            {
                                                int tdIndex = maybeBKBoardList.FindIndex(item => item.BoardUID.Equals(TDBUID));
                                                if (tdIndex != -1)
                                                    maybeBKBoardList.RemoveAt(tdIndex);
                                            }
                                            if(BushItemList.Count > 0)
                                            {
                                                List<string> aboutBushBUIDList = new List<string>();
                                                for(int bui = 0; bui < BushItemList.Count; bui++)
                                                {
                                                    if(BushItemList[bui].BushBoardList.Count > 0)
                                                    {
                                                        List<string> tempbushBUIDList  = BushItemList[bui].BushBoardList.Select(item => item.BoardUID).ToList();
                                                        aboutBushBUIDList.AddRange(tempbushBUIDList);
                                                    }
                                                    if (BushItemList[bui].BushTDBoard.BoardUID != null)
                                                        aboutBushBUIDList.Add(BushItemList[bui].BushTDBoard.BoardUID);
                                                }
                                                if (aboutBushBUIDList.Count > 0)
                                                {
                                                    aboutBushBUIDList = aboutBushBUIDList.Distinct().ToList();
                                                    for (int bui = 0; bui < aboutBushBUIDList.Count; bui++)
                                                    {
                                                        int bushIndex = maybeBKBoardList.FindIndex(item => item.BoardUID.Equals(aboutBushBUIDList[bui]));
                                                        if (bushIndex != -1)
                                                            maybeBKBoardList.RemoveAt(bushIndex);
                                                    }
                                                }
                                            }

                                            if(maybeBKBoardList.Count> 0)
                                            {
                                                List<double> maybeBKKeys = new List<double>();
                                                List<double> avKeyList = AVLineYDic.Keys.ToList();
                                                for (int bki = 0; bki < maybeBKBoardList.Count; bki++)
                                                {
                                                    double maxY = Math.Round(maybeBKBoardList[bki].OverheadLine.StartPoint.TransSplitPoint .Y,1) + 0.5;
                                                    double minY = Math.Round(maybeBKBoardList[bki].BottomLine.StartPoint.TransSplitPoint.Y,1) - 0.5;
                                                    List<double> tempScopeKeys =  avKeyList.FindAll(item => minY <= item && item <= maxY);
                                                    if (tempScopeKeys.Count > 0)
                                                        maybeBKKeys.AddRange(tempScopeKeys);
                                                }
                                                List<MixedCAD_Line> BKVLines = new List<MixedCAD_Line>();
                                                if (maybeBKKeys.Count > 0)
                                                    maybeBKKeys.ForEach(key => BKVLines.AddRange(AVLineYDic[key]));
                                                if(BKVLines.Count > 0)
                                                {
                                                    //Merge BK Vline
                                                    if (BKVLines.Count > 1)
                                                        BKVLines = ComputedUtils.MergeSimilarXVLineList(BKVLines);

                                                    if (CADCommonForm.MoldTypeStr.Equals("PP"))
                                                    {
                                                        if (FangtieShareData.HasLRF)
                                                        {
                                                            if (FangtieShareData.SPAnotherFX == FangtieShareData.FLXInfo.SplitX)
                                                                BKVLines = BKVLines.FindAll(item => item.StartPoint.CustomerPoint.X > AllowRX);
                                                            if (FangtieShareData.SPAnotherFX == FangtieShareData.FRXInfo.SplitX)
                                                                BKVLines = BKVLines.FindAll(item => item.StartPoint.CustomerPoint.X < AllowLX);
                                                        }
                                                    }
                                                    else
                                                        if (FangtieShareData.HasLRF)
                                                        BKVLines = BKVLines.FindAll(item => item.StartPoint.CustomerPoint.X < AllowLX || item.StartPoint.CustomerPoint.X > AllowRX);

                                                    if (BKVLines.Count > 0 && AVTDRealCenterX != null)
                                                    {
                                                        double BKrefX = (double)AVTDRealCenterX;
                                                        ScrewHole refScrewHole = GPList[0];

                                                        double refBSV = ParamsConfigData.StandardGPList.Find(item => item.Dimension == SItem.Dim).BushSize;
                                                        for (int j = 0; j < BKVLines.Count - 1; j++)
                                                        {
                                                            for (int k = 1; k < BKVLines.Count; k++)
                                                            {
                                                                if (k > j)
                                                                {
                                                                    Boolean diffLengthF = Math.Abs(BKVLines[j].Length - BKVLines[k].Length) < 3;
                                                                    double TempDim = Math.Abs(BKVLines[j].StartPoint.TransSplitPoint.X - BKVLines[k].StartPoint.TransSplitPoint.X);
                                                                    //近似中心对称 计算误差在+- 0.2
                                                                    double TwoLineSplitAgvCX = Math.Round((BKVLines[j].StartPoint.TransSplitPoint.X 
                                                                        + BKVLines[k].StartPoint.TransSplitPoint.X) / 2, 1);
                                                                    double LX = TwoLineSplitAgvCX - 5;
                                                                    double RX = TwoLineSplitAgvCX + 5;
                                                                    Boolean satF = LX <= BKrefX && BKrefX <= RX;
                                                                    if (satF)
                                                                    {
                                                                        Boolean F1 = refScrewHole.BK - 5 <= TempDim && TempDim <= refScrewHole.BK + 2;
                                                                        Boolean F2 = SItem.Dim <TempDim && TempDim < refBSV;
                                                                        if (F1 && F2 && diffLengthF)
                                                                        {
                                                                            CSinglePartItem GPBKItem = new CSinglePartItem();
                                                                            GPBKItem.ItemType = ItemPartCodeType.BK;
                                                                            GPBKItem.LLine = BKVLines[j];
                                                                            GPBKItem.RLine = BKVLines[k];
                                                                            GPBKItem.XLength = TempDim;
                                                                            GPBKItem.YLength = Math.Round(Math.Abs(BKVLines[j].StartPoint.CustomerPoint.Y 
                                                                                - BKVLines[k].EndPoint.CustomerPoint.Y), 0);
                                                                            GPBKItem.TVCPX = BKrefX;
                                                                            AllRelatedBKVList.Add(GPBKItem);
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }

                                                List<ItemBKInfo> ResBKInfoList = new List<ItemBKInfo>();
                                                //GP 直径通孔板 = (GP Board - GP TD Board - 套)疑似避空区域 -避空
                                                List<BoardSectionItem> maybeDimThroughBList = (List<BoardSectionItem>)ConvertUtils.DeepCopyObject(maybeBKBoardList);
                                                maybeDimThroughBList = maybeDimThroughBList.FindAll(item => !item.BoardCode.Equals("fpBoard")
                                                && !item.BoardCode.Equals("epBoard"));
                                                if (AllRelatedBKVList.Count > 0)
                                                {
                                                    List<double> BKValueList = AllRelatedBKVList.Select(item => item.XLength).Distinct().ToList();
                                                    SItem.BK = (int)BKValueList.Max();
                                                    for(int bki = 0; bki < AllRelatedBKVList.Count; bki++)
                                                    {
                                                        List<DeadReckBKTempInfo> tempBKDetailList = new List<DeadReckBKTempInfo>();
                                                        double LSY = AllRelatedBKVList[bki].LLine.StartPoint.CustomerPoint.Y;
                                                        double LEY = AllRelatedBKVList[bki].LLine.EndPoint.CustomerPoint.Y;
                                                        double RSY = AllRelatedBKVList[bki].RLine.StartPoint.CustomerPoint.Y;
                                                        double REY = AllRelatedBKVList[bki].RLine.EndPoint.CustomerPoint.Y;
                                                        double tempbkH = Math.Round(AllRelatedBKVList[bki].YLength,1);
                                                        double TY = LSY < RSY ? LSY : RSY;
                                                        double BY = LEY > REY ? LEY : REY;
                                                        int FirstBoardIndex = maybeBKBoardList.FindLastIndex(item => TY <= item.OverheadLine.StartPoint.CustomerPoint.Y);
                                                        int SecondBoardIndex = maybeBKBoardList.FindIndex(item => item.BottomLine.StartPoint.CustomerPoint.Y <= BY);
                                                        if (FirstBoardIndex != -1 && SecondBoardIndex != -1 && SecondBoardIndex >= FirstBoardIndex)
                                                        {
                                                            List<BoardSectionItem> TempAreaBList = maybeBKBoardList.GetRange(FirstBoardIndex, SecondBoardIndex - FirstBoardIndex + 1);
                                                            if(TempAreaBList.Count > 0)
                                                                TempAreaBList = TempAreaBList.FindAll(item => !item.BoardCode.Equals("fpBoard")
                                                                     && !item.BoardCode.Equals("epBoard"));
                                                            if (TempAreaBList.Count > 0)
                                                            {
                                                                TempAreaBList = TempAreaBList.OrderBy(item => item.plateLineNo).ToList();
                                                                ItemBKInfo tempbkInfo = new ItemBKInfo();
                                                                tempbkInfo.BKHH = tempbkH;
                                                                if (TempAreaBList.Count == 1)
                                                                {
                                                                    BoardSectionItem targetBKBItem = TempAreaBList.First();
                                                                    double bkbthick = Math.Round(targetBKBItem.PlateThick,1);
                                                                    if(tempbkH == bkbthick)
                                                                    {
                                                                        DeadReckBKTempInfo tempbkdetail = new DeadReckBKTempInfo();
                                                                        tempbkdetail.BKInBoardUID = targetBKBItem.BoardUID;
                                                                        tempbkdetail.H = tempbkH;
                                                                        tempbkdetail.BKInBoardType = InBoardType.Through;
                                                                        tempBKDetailList.Add(tempbkdetail);
                                                                    }
                                                                    else
                                                                    {
                                                                        if(tempbkH < bkbthick)
                                                                        {
                                                                            double bty = Math.Round(targetBKBItem.OverheadLine.StartPoint.CustomerPoint.Y,1);
                                                                            double bby = Math.Round(targetBKBItem.BottomLine.StartPoint.CustomerPoint.Y,1);
                                                                            Boolean F1 = Math.Round(TY,1) == bty;
                                                                            Boolean F2 = Math.Round(BY,1) == bby;
                                                                            DeadReckBKTempInfo tempbkdetail = new DeadReckBKTempInfo();
                                                                            if (F1)
                                                                                tempbkdetail.BKInBoardType = InBoardType.Up;
                                                                            if (F2)
                                                                                tempbkdetail.BKInBoardType = InBoardType.Down;
                                                                            tempbkdetail.BKInBoardUID = targetBKBItem.BoardUID;
                                                                            tempbkdetail.H = tempbkH;
                                                                            tempBKDetailList.Add(tempbkdetail);
                                                                        }
                                                                    }
                                                                }
                                                                //避空连板
                                                                else
                                                                {
                                                                    
                                                                    double bkBoardH = 0;
                                                                    TempAreaBList.ForEach(item => bkBoardH += item.PlateThick);
                                                                    bkBoardH = Math.Round(bkBoardH, 1);
                                                                    if(tempbkH == bkBoardH)
                                                                    {
                                                                        for (bki = 0; bki < TempAreaBList.Count; bki++)
                                                                        {
                                                                            DeadReckBKTempInfo tempbkdetail = new DeadReckBKTempInfo();
                                                                            tempbkdetail.BKInBoardType = InBoardType.Through;
                                                                            tempbkdetail.BKInBoardUID = TempAreaBList[bki].BoardUID;
                                                                            tempbkdetail.H = TempAreaBList[bki].PlateThick;
                                                                            tempBKDetailList.Add(tempbkdetail);
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        if(tempbkH < bkBoardH)
                                                                        {
                                                                            double diffH = bkBoardH - tempbkH;
                                                                            BoardSectionItem firstBKBItem = TempAreaBList.First();
                                                                            BoardSectionItem lastBKBItem = TempAreaBList.Last();
                                                                            double bty = Math.Round(firstBKBItem.OverheadLine.StartPoint.CustomerPoint.Y, 1);
                                                                            double bby = Math.Round(lastBKBItem.BottomLine.StartPoint.CustomerPoint.Y, 1);
                                                                            Boolean F1 = Math.Round(TY, 1) == bty;
                                                                            Boolean F2 = Math.Round(BY, 1) == bby;
                                                                            if (F1)
                                                                            {
                                                                                DeadReckBKTempInfo lastbkInfo = new DeadReckBKTempInfo();
                                                                                double lastbkH = lastBKBItem.PlateThick - diffH;
                                                                                lastbkInfo.BKInBoardType = InBoardType.Up;
                                                                                lastbkInfo.BKInBoardUID = lastBKBItem.BoardUID;
                                                                                lastbkInfo.H = lastbkH;
                                                                                tempBKDetailList.Add(lastbkInfo);
                                                                                List<BoardSectionItem> operBList = (List<BoardSectionItem>)ConvertUtils.DeepCopyObject(TempAreaBList);
                                                                                operBList.RemoveAt(operBList.Count - 1);
                                                                                if(operBList.Count > 0)
                                                                                {
                                                                                    for(int op = 0;op < operBList.Count; op++)
                                                                                    {
                                                                                        DeadReckBKTempInfo tempbkdetail = new DeadReckBKTempInfo();
                                                                                        tempbkdetail.BKInBoardType = InBoardType.Through;
                                                                                        tempbkdetail.BKInBoardUID = operBList[op].BoardUID;
                                                                                        tempbkdetail.H = operBList[op].PlateThick;
                                                                                        tempBKDetailList.Add(tempbkdetail);
                                                                                    }
                                                                                }
                                                                            }
                                                                            if (F2)
                                                                            {
                                                                                DeadReckBKTempInfo firstbkInfo = new DeadReckBKTempInfo();
                                                                                double firstbkH = firstBKBItem.PlateThick - diffH;
                                                                                firstbkInfo.BKInBoardType = InBoardType.Down;
                                                                                firstbkInfo.BKInBoardUID = firstBKBItem.BoardUID;
                                                                                firstbkInfo.H = firstbkH;
                                                                                tempBKDetailList.Add(firstbkInfo);
                                                                                List<BoardSectionItem> operBList = (List<BoardSectionItem>)ConvertUtils.DeepCopyObject(TempAreaBList);
                                                                                operBList.RemoveAt(0);
                                                                                if (operBList.Count > 0)
                                                                                {
                                                                                    for (int op = 0; op < operBList.Count; op++)
                                                                                    {
                                                                                        DeadReckBKTempInfo tempbkdetail = new DeadReckBKTempInfo();
                                                                                        tempbkdetail.BKInBoardType = InBoardType.Through;
                                                                                        tempbkdetail.BKInBoardUID = operBList[op].BoardUID;
                                                                                        tempbkdetail.H = operBList[op].PlateThick;
                                                                                        tempBKDetailList.Add(tempbkdetail);
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                                
                                                                if (tempBKDetailList.Count > 0)
                                                                {
                                                                    tempBKDetailList = tempBKDetailList.Distinct(new DeadReckBKTempInfoComparer()).ToList();
                                                                    List<string> BoardUIDList = tempBKDetailList.Select(item => item.BKInBoardUID).ToList();
                                                                    tempbkInfo.BoardUIDList.AddRange(BoardUIDList);
                                                                    tempbkInfo.DetailInfoList.AddRange(tempBKDetailList);
                                                                }
                                                                ResBKInfoList.Add(tempbkInfo);
                                                            }
                                                        }
                                                    }
                                                    if(ResBKInfoList.Count > 0)
                                                    {
                                                        ResBKInfoList = ResBKInfoList.Distinct(new ItemBKInfoComparer()).ToList();
                                                        SItem.ItemBKInfoList.AddRange(ResBKInfoList);
                                                        List<List<string>> BUIDList = ResBKInfoList.Select(item => item.BoardUIDList).ToList();
                                                        List<string> resBUIDList = new List<string>();
                                                        BUIDList.ForEach(item => resBUIDList.AddRange(item));
                                                        resBUIDList = resBUIDList.Distinct().ToList();
                                                        for (int ti = 0; ti < resBUIDList.Count; ti++)
                                                        {
                                                            Boolean hasF = resBUIDList[ti].Contains("fangtie");
                                                            if (hasF)
                                                                maybeDimThroughBList = maybeDimThroughBList.FindAll(item => !item.BoardUID.Contains("fangtie"));
                                                            int delIndex = maybeDimThroughBList.FindIndex(item => item.BoardUID.Equals(resBUIDList[ti]));
                                                            if (delIndex != -1)
                                                                maybeDimThroughBList.RemoveAt(delIndex);
                                                        }
                                                        
                                                        if (maybeDimThroughBList.Count > 0)
                                                            SItem.ItemDimThroughHBList = maybeDimThroughBList;
                                                    }
                                                }
                                                //没有避空  GP 直径通孔板 = (GP Board - GP TD Board - 套)
                                                else
                                                    SItem.ItemDimThroughHBList = maybeDimThroughBList;
                                            }

                                        }

                                        SItem.ItemCode = "GuidePin";
                                        CU.SPGPTransToProcessData("GP", SItem);
                                        ShareItemData.ItemList.Add(SItem);
                                    }
                                }

                            }
                        }

                    }

                }
            }
            catch (Exception ex)
            {
                var ee = ex;
            }

        }

        //专门处理投影图 EGP相关的圆
        public static Dictionary<CircleKey, List<MixedCAD_Circle>> ProcessTVMayBeEGP(Dictionary<CircleKey, List<MixedCAD_Circle>> ConnCircleDic, 
            List<MixedCAD_Text> TextList)
        {
            Dictionary<CircleKey, List<MixedCAD_Circle>> ResDic = new Dictionary<CircleKey, List<MixedCAD_Circle>>();
            List<MixedCAD_Text> EGPCPList = TextList.FindAll(item => item.Centent.Contains("EGP")).ToList();
            List<MixedCAD_Circle> CCList = new List<MixedCAD_Circle>();
            List<MixedCAD_Circle> ATVOriginCList = new List<MixedCAD_Circle>();
            List<MixedCAD_Circle> ATVTargetCList = new List<MixedCAD_Circle>();

            List<CircleKey> CCPKeysList = ConnCircleDic.Keys.ToList();
            for (int i = 0; i < CCPKeysList.Count; i++)
                ATVOriginCList.AddRange(ConnCircleDic[CCPKeysList[i]]);

            if (EGPCPList.Count > 0 && ATVOriginCList.Count > 0)
            {
                for (int i = 0; i < EGPCPList.Count; i++)
                {
                    //if 非块 EGP中心附近+-20找
                    for (int j = 0; j < ATVOriginCList.Count; j++)
                    {
                        double LX = EGPCPList[i].PositionPoint.CustomerPoint.X - 20;
                        double RX = EGPCPList[i].PositionPoint.CustomerPoint.X + 20;
                        double BY = EGPCPList[i].PositionPoint.CustomerPoint.Y - 20;
                        double TY = EGPCPList[i].PositionPoint.CustomerPoint.Y + 20;
                        Boolean F1 = LX <= ATVOriginCList[j].CenterPoint.CustomerPoint.X && ATVOriginCList[j].CenterPoint.CustomerPoint.X <= RX;
                        Boolean F2 = BY <= ATVOriginCList[j].CenterPoint.CustomerPoint.Y && ATVOriginCList[j].CenterPoint.CustomerPoint.Y <= TY;
                        //基本可以确定是同心
                        if (F1 && F2)
                            CCList.Add(ATVOriginCList[j]);
                    }
                }
            }

            if (CCList.Count > 0)
                ResDic = CU.ProcessEGPConCircles(CCList);

            return ResDic;
        }

        public static void RecognizeEGP(Dictionary<double, List<MixedCAD_Line>> AVLineYDic,List<MixedCAD_Arc> AArcList)
        {
            /**
            * if = 2，针板导柱位于中轴线上，
            * if = 4 针板导柱的中心线与回针的中心线在同一竖线方向上 
            * 针板导柱的上下两段在组装图中位于在底板以及方铁的上一层板
            */
            List<SingleItem> tempEGPItemList = new List<SingleItem>();
            try
            {
                CU.EGPHoleArg();
                List<ScrewHole> EGPList = HoleCandidateShareData.EGPScrewCList;
                List<BoardSectionItem> BList = AssemblyShareData.ASectionList;
                ScrewHole RefEGPHole = EGPList[0];
                //有EGP孔参数 开始识别
                if (EGPList.Count > 0)
                {
                    //EGP零件集合
                    List<CSingleItem> CTempPList = new List<CSingleItem>();
                    //组装图上 导套各部位竖线集合
                    List<CSinglePartItem> EGPItemVList = new List<CSinglePartItem>();
                    int fangtieIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("fangtie"));
                    //方铁的上一层板
                    int PerFIndex = fangtieIndex - 1;
                    //在底板上寻找导柱的托位
                    int bpBoardIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("bpBoard"));
                    List<BoardSectionItem> MBGPList = AssemblyShareData.ASectionList.GetRange(PerFIndex, AssemblyShareData.ASectionList.Count - PerFIndex);
                    //在针板X范围内查找
                    BoardSectionItem fpBoardBoard = AssemblyShareData.ASectionList.Find(item => item.BoardCode.Equals("fpBoard"));
                   
                    double LX = fpBoardBoard.BottomLine.UseStartPoint.X;
                    double RX = fpBoardBoard.BottomLine.UseEndPoint.X;
                    if(fpBoardBoard != null && MBGPList.Count > 0)
                    {
                        double MBGPMaxY = Math.Round(MBGPList.First().OverheadLine.UseStartPoint.Y, 0);
                        double MBGPMinY = Math.Round(MBGPList.Last().BottomLine.UseStartPoint.Y, 0);
                        //竖 候选线
                        List<MixedCAD_Line> MBGPVLines = new List<MixedCAD_Line>();
                        List<double> BoardVLineKeys = AVLineYDic.Keys.ToList().FindAll(item => MBGPMinY <= Math.Round(item, 0) 
                        && Math.Round(item, 0) <= MBGPMaxY);
                        if (BoardVLineKeys != null)
                            BoardVLineKeys.ForEach(key => MBGPVLines.AddRange(AVLineYDic[key]));
                        MBGPVLines = MBGPVLines.FindAll(item => LX <= item.StartPoint.UsePoint.X && item.StartPoint.UsePoint.X <= RX);

                        if (MBGPVLines.Count > 0)
                        {
                            for (int i = 0; i < MBGPVLines.Count - 1; i++)
                            {
                                for (int j = 1; j < MBGPVLines.Count; j++)
                                {
                                    if (j > i)
                                    {
                                        for (int k = 0; k < EGPList.Count; k++)
                                        {
                                            double TempDim = Math.Abs(MBGPVLines[i].StartPoint.UsePoint.X - MBGPVLines[j].StartPoint.UsePoint.X);
                                            double TwoLineSplitAgvCX = Math.Round((MBGPVLines[i].StartPoint.UsePoint.X + MBGPVLines[j].StartPoint.UsePoint.X) / 2, 0);
                                            double TwoLineCustomerAgvCX = Math.Round((MBGPVLines[i].StartPoint.CustomerPoint.X 
                                                + MBGPVLines[j].StartPoint.CustomerPoint.X) / 2, 1);
                                            double TargetCenterX = Math.Round(EGPList[k].CenterPoint.TransSplitPoint.X, 0);
                                            if (TargetCenterX - 0.2 <= TwoLineSplitAgvCX && TwoLineSplitAgvCX <= TargetCenterX + 0.2)
                                            {
                                                CSinglePartItem MBGPItem = new CSinglePartItem();
                                                if (EGPList[k].Dim - 0.02 <= TempDim && TempDim <= EGPList[k].Dim + 0.02)
                                                {
                                                    //直径
                                                    MBGPItem.ItemType = ItemPartCodeType.Dim;
                                                    MBGPItem.LLine = MBGPVLines[i];
                                                    MBGPItem.RLine = MBGPVLines[j];
                                                    MBGPItem.XLength = TempDim;
                                                    MBGPItem.YLength = Math.Round(Math.Abs(MBGPVLines[i].StartPoint.CustomerPoint.Y 
                                                        - MBGPVLines[i].EndPoint.CustomerPoint.Y), 0);
                                                    MBGPItem.AVSplitCX = TwoLineSplitAgvCX;
                                                    MBGPItem.AVCustomerCX = TwoLineCustomerAgvCX;
                                                    MBGPItem.MatchScrewHole = EGPList[k];
                                                    EGPItemVList.Add(MBGPItem);
                                                }
                                                double TDEY = MBGPVLines[i].EndPoint.TransSplitPoint.Y;
                                                Boolean TDF1 = TDEY - 2 <= MBGPMinY && MBGPMinY <= TDEY + 2;
                                                Boolean TDF2 = EGPList[k].TD - 1 <= TempDim && TempDim <= EGPList[k].TD + 1;
                                                if (TDF1 && TDF2)
                                                {
                                                    //托位
                                                    MBGPItem.ItemType = ItemPartCodeType.TD;
                                                    MBGPItem.LLine = MBGPVLines[i];
                                                    MBGPItem.RLine = MBGPVLines[j];
                                                    MBGPItem.XLength = TempDim;
                                                    MBGPItem.YLength = Math.Round(Math.Abs(MBGPVLines[i].StartPoint.CustomerPoint.Y
                                                        - MBGPVLines[i].EndPoint.CustomerPoint.Y), 0);
                                                    MBGPItem.AVSplitCX = TwoLineSplitAgvCX;
                                                    MBGPItem.AVCustomerCX = TwoLineCustomerAgvCX;
                                                    MBGPItem.MatchScrewHole = EGPList[k];
                                                    EGPItemVList.Add(MBGPItem);
                                                }
                                                if (EGPList[k].BushSize - 2 <= TempDim && TempDim <= EGPList[k].BushSize + 2)
                                                {
                                                    //导套外径
                                                    MBGPItem.ItemType = ItemPartCodeType.BushSize;
                                                    MBGPItem.LLine = MBGPVLines[i];
                                                    MBGPItem.RLine = MBGPVLines[j];
                                                    MBGPItem.XLength = TempDim;
                                                    MBGPItem.YLength = Math.Round(Math.Abs(MBGPVLines[i].StartPoint.CustomerPoint.Y 
                                                        - MBGPVLines[i].EndPoint.CustomerPoint.Y), 0);
                                                    MBGPItem.AVSplitCX = TwoLineSplitAgvCX;
                                                    MBGPItem.AVCustomerCX = TwoLineCustomerAgvCX;
                                                    MBGPItem.MatchScrewHole = EGPList[k];
                                                    EGPItemVList.Add(MBGPItem);
                                                }
                                                if (EGPList[k].BushTD - 1 <= TempDim && TempDim <= EGPList[k].BushTD + 1)
                                                {
                                                    //导套托位
                                                    MBGPItem.ItemType = ItemPartCodeType.BushTD;
                                                    MBGPItem.LLine = MBGPVLines[i];
                                                    MBGPItem.RLine = MBGPVLines[j];
                                                    MBGPItem.XLength = TempDim;
                                                    MBGPItem.YLength = Math.Round(Math.Abs(MBGPVLines[i].StartPoint.CustomerPoint.Y 
                                                        - MBGPVLines[i].EndPoint.CustomerPoint.Y), 0);
                                                    MBGPItem.AVSplitCX = TwoLineSplitAgvCX;
                                                    MBGPItem.AVCustomerCX = TwoLineCustomerAgvCX;
                                                    MBGPItem.MatchScrewHole = EGPList[k];
                                                    EGPItemVList.Add(MBGPItem);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        if (EGPItemVList.Count > 0)
                        {
                            List<CSinglePartItem> resList = new List<CSinglePartItem>();
                            resList.Add(EGPItemVList[0]);
                            if (EGPItemVList.Count > 1)
                            {
                                for (int i = 1; i < EGPItemVList.Count; i++)
                                {
                                    Boolean NoSameFlag = resList.FindIndex(item => CU.JudgeEqualItemPart(item, EGPItemVList[i])) == -1;
                                    if (NoSameFlag)
                                        resList.Add(EGPItemVList[i]);
                                }
                            }
                            EGPItemVList = resList;
                        }

                        //合并EGP中托边
                        if (EGPItemVList.Count > 0)
                        {
                            var GroupByList = EGPItemVList.GroupBy(item => item.AVSplitCX);
                            foreach (var Item in GroupByList)
                            {
                                List<CSinglePartItem> ItemPartList = Item.ToList();
                                CSingleItem CItem = new CSingleItem();
                                CItem.AVSplitCX = Item.Key;
                                for (int i = 0; i < ItemPartList.Count; i++)
                                {
                                    CItem.MatchScrewHole = ItemPartList[i].MatchScrewHole;
                                    CItem.InfoList.Add(ItemPartList[i]);
                                }
                                CTempPList.Add(CItem);
                            }
                        }

                        CTempPList = CTempPList.FindAll(item => item.InfoList.FindIndex(info => info.ItemType == ItemPartCodeType.Dim) != -1);
                        CTempPList = CTempPList.FindAll(item => item.InfoList.Select(info => info.ItemType).ToList().Count > 1);

                        if (CTempPList.Count > 0)
                        {
                            List<CSingleItem> ResCTempList = new List<CSingleItem>();
                            List<BoardSectionItem> BoardList = AssemblyShareData.ASectionList;
                            double lastBEY = BoardList[BoardList.Count - 1].BottomLine.UseStartPoint.Y;

                            for (int i = 0; i < CTempPList.Count; i++)
                            {
                                List<CSinglePartItem> TDPartList = CTempPList[i].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD);
                                if (TDPartList.Count > 0)
                                {
                                    List<double> TDEPList = TDPartList.Select(item => item.LLine.EndPoint.TransSplitPoint.Y).ToList();
                                    int tdIndex = TDEPList.FindIndex(item => item - 2 <= lastBEY && lastBEY <= item + 2);
                                    if (tdIndex != -1)
                                        ResCTempList.Add(CTempPList[i]);
                                }
                            }
                            CTempPList = ResCTempList;
                        }

                        //各部分参数
                        if (CTempPList.Count > 0)
                        {
                            for (int i = 0; i < CTempPList.Count; i++)
                                CTempPList[i].RelScrewHoleList = EGPList.FindAll(item =>
                                (CTempPList[i].MatchScrewHole.Dim - 0.01 <= item.Dim && item.Dim <= CTempPList[i].MatchScrewHole.Dim + 0.01)
                                &&
                                (CTempPList[i].MatchScrewHole.TD - 0.01 <= item.TD && item.TD <= CTempPList[i].MatchScrewHole.TD + 0.01));

                            for (int k = 0; k < CTempPList.Count; k++)
                            {
                                SingleItem EGPItem = new SingleItem();
                                EGPItem.ItemUID = EGPItem.ItemName + ShareItemData.ItemList.Count().ToString();
                                EGPItem.ItemCode = "EGPPin";
                                EGPItem.ItemNameType = DItemNameType.EGPPin;
                                EGPItem.RelScrewHoleList = EGPList;
                                EGPItem.ItemNum = EGPItem.RelScrewHoleList.Count;
                                double EGPDim = 0;
                                double EGPTD = 0;
                                double EGPBushTD = 0;
                                double BushSize = 0;
                                List<CSinglePartItem> TempPartList = CTempPList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.Dim).ToList();
                                if (TempPartList.Count > 0)
                                    EGPDim = TempPartList.Select(item => item.XLength).Distinct().Min();
                                //根据托位落在哪块板来判断 安装方式
                                TempPartList = CTempPList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD).ToList();
                                //EGP TD 默认
                                InBoardPosType EGPPosType = InBoardPosType.BoardDown;
                                BoardSectionItem TDInBoard = AssemblyShareData.ASectionList[AssemblyShareData.ASectionList.Count - 1];
                                TempPartList = CTempPList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.BushTD).ToList();
                                if (TempPartList.Count > 0)
                                    EGPBushTD = TempPartList.Select(item => item.XLength).Distinct().Min();
                                TempPartList = CTempPList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.BushSize).ToList();
                                if (TempPartList.Count > 0)
                                    BushSize = TempPartList.Select(item => item.XLength).Distinct().Min();
                                EGPItem.BushSize = Convert.ToInt32(BushSize);
                                EGPItem.Dim = EGPDim;
                                EGPItem.TD = Convert.ToDecimal(EGPTD);
                                EGPItem.AVCustomerCX = CTempPList[k].CenterPoint.CustomerPoint.X;
                                EGPItem.AVSplitCX = CTempPList[k].AVSplitCX;
                                EGPItem.BushTD = Convert.ToInt32(EGPBushTD);
                                TempPartList = CTempPList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.Dim);
                                
                                //Dim Arc Scope Board
                                List<BoardSectionItem> DimArcScopeBList = new List<BoardSectionItem>();
                                int MBPfpBIndex = MBGPList.FindIndex(item => item.BoardCode.Equals("fpBoard"));
                                DimArcScopeBList = MBGPList.GetRange(0, MBPfpBIndex);
                                if(DimArcScopeBList.Count > 0)
                                {
                                    List<MixedCAD_Arc> DimArcList = new List<MixedCAD_Arc>();
                                    double dimArcMaxY = DimArcScopeBList.Select(item => item.OverheadLine.StartPoint.CustomerPoint.Y).Max();
                                    double dimArcMinY = DimArcScopeBList.Select(item => item.BottomLine.StartPoint.CustomerPoint.Y).Min();
                                    DimArcList = AArcList.FindAll(item => dimArcMinY <= item.CenterPoint.CustomerPoint.Y
                                        && item.CenterPoint.CustomerPoint.Y <= dimArcMaxY);
                                    if(DimArcList.Count > 0)
                                    {
                                        double DLX = EGPItem.AVSplitCX - Convert.ToDouble(EGPItem.Dim / 2);
                                        double DRX = EGPItem.AVSplitCX + Convert.ToDouble(EGPItem.Dim / 2);
                                        DimArcList = DimArcList.FindAll(item => DLX <= item.CenterPoint.TransSplitPoint.X
                                        && item.CenterPoint.TransSplitPoint.X <= DRX);
                                    }
                                    if(DimArcList.Count > 0)
                                    {
                                        List<CSinglePartItem> TDCSPartList = CTempPList[k].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD).ToList();
                                        if(TDCSPartList.Count > 0)
                                        {
                                            List<double> TDYList = new List<double>();
                                            for(int ti = 0; ti < TDCSPartList.Count; ti++)
                                            {
                                                double Y1 = TDCSPartList[ti].LLine.StartPoint.CustomerPoint.Y;
                                                double Y2 = TDCSPartList[ti].LLine.EndPoint.CustomerPoint.Y;
                                                double Y3 = TDCSPartList[ti].RLine.StartPoint.CustomerPoint.Y;
                                                double Y4 = TDCSPartList[ti].RLine.EndPoint.CustomerPoint.Y;
                                                TDYList.Add(Y1);
                                                TDYList.Add(Y2);
                                                TDYList.Add(Y3);
                                                TDYList.Add(Y4);
                                            }
                                            if(TDYList.Count > 0)
                                            {
                                                double TDMinY = TDYList.Min(item => item);
                                                double EGPY = 0;
                                                double dimMaxY = DimArcList.Max(CItem => CItem.StartPoint.CustomerPoint.Y);
                                                MixedCAD_Arc BushMostYArcItem = DimArcList.Find(item => item.StartPoint.CustomerPoint.Y ==
                                                dimMaxY);
                                                EGPY = Math.Round(BushMostYArcItem.StartPoint.CustomerPoint.Y - TDMinY, 0);
                                                EGPItem.PeakY = TDInBoard.BottomLine.StartPoint.CustomerPoint.Y;
                                                EGPItem.NadirY = BushMostYArcItem.StartPoint.CustomerPoint.Y;
                                                EGPItem.RealH = Convert.ToInt32(Math.Round(EGPY, 0));
                                            }

                                            BoardSectionItem tempLFB = AssemblyShareData.ASectionList.FindLast(item => item.BoardCode.Equals("fangtie"));
                                            BoardSectionItem tempbpB = AssemblyShareData.ASectionList[bpBoardIndex];
                                            double TY = tempLFB.OverheadLine.StartPoint.CustomerPoint.Y;
                                            double BY = tempbpB.BottomLine.StartPoint.CustomerPoint.Y;
                                            //中托边理论长度 Dim∮12-∮20，伸入B板（托板）15mm；>=∮25 伸入B板（托板）20mm
                                            double MorePassL = 0;
                                            if (12 <= EGPItem.Dim && EGPItem.Dim <= 20)
                                                MorePassL = 15;
                                            if (EGPItem.Dim >= 25)
                                                MorePassL = 20;
                                            EGPItem.TheoryH = Math.Round(TY - BY, 0) + MorePassL;
                                            EGPItem.TheoryH = ComputedUtils.RepScrewItemLRule(EGPItem.TheoryH);
                                            int firstFIndex = BList.FindIndex(item => item.BoardCode.Equals("fangtie"));
                                            if (firstFIndex != -1)
                                            {
                                                if (firstFIndex - 1 >= 0)
                                                    EGPItem.BlindHoleBoard = BList[firstFIndex - 1];
                                            }
                                            EGPItem.TDBoard = BList[BList.Count - 1];

                                            //设置所在板区间
                                            EGPItem.TDBoard = TDInBoard;
                                            //排掉托位 直径
                                            List<BoardSectionItem> DimInBoardList = MBGPList.FindAll(item => !item.BoardUID.Equals(TDInBoard.BoardUID));
                                            
                                            EGPItem.ScrewDimThroughHBList = MBGPList.FindAll(item => !item.BoardUID.Equals(EGPItem.BlindHoleBoard.BoardUID)
                                            && !item.BoardCode.Equals("fangtie"));

                                            StandardEGP targetStandardParams = CU.ComputedSAboutEGPParams((int)EGPItem.Dim);
                                            EGPItem.Dim = targetStandardParams.Dimension;
                                            EGPItem.InputTD = targetStandardParams.TD;
                                            EGPItem.InputTH = targetStandardParams.TH;

                                        }
                                    }
                                }

                                RefHoleCenterSplitInfo SInfo = TranRefCHoleData(EGPItem.ItemNameType, EGPItem.RelScrewHoleList);
                                EGPItem.HSplitInfo = SInfo;

                                if (TempPartList.Count > 0)
                                {
                                    List<MixedCAD_Arc> BushArcList = new List<MixedCAD_Arc>();
                                    List<BoardSectionItem> epfpScopeBList = MBGPList.FindAll(item => item.BoardCode.Equals("epBoard") 
                                    || item.BoardCode.Equals("fpBoard"));
                                    double bushBScopeMaxY = epfpScopeBList.Select(item => item.OverheadLine.StartPoint.CustomerPoint.Y).Max();
                                    double bushBScopeMinY = epfpScopeBList.Select(item => item.BottomLine.StartPoint.CustomerPoint.Y).Min();
                                    bushBScopeMaxY += 5;
                                    bushBScopeMinY -= 5;
                                    BushArcList = AArcList.FindAll(item => bushBScopeMinY <= item.CenterPoint.CustomerPoint.Y
                                        && item.CenterPoint.CustomerPoint.Y <= bushBScopeMaxY);
                                    int FfpBIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("fpBoard"));
                                    int FepBIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("epBoard"));
                                    if (FfpBIndex != -1 && FepBIndex != -1)
                                    {
                                        if (BushArcList.Count > 0)
                                        {
                                            double TDLX = EGPItem.AVSplitCX - Convert.ToDouble(EGPItem.BushTD / 2);
                                            double TDRX = EGPItem.AVSplitCX + Convert.ToDouble(EGPItem.BushTD / 2);
                                            // 圆心落在 托位范围内  (中托司圆弧候选集)
                                            BushArcList = BushArcList.FindAll(item => TDLX <= item.CenterPoint.TransSplitPoint.X
                                            && item.CenterPoint.TransSplitPoint.X <= TDRX);
                                            if (BushArcList.Count > 0)
                                            {
                                                SingleItem EGPBushItem = new SingleItem();
                                                EGPBushItem.ItemUID = EGPBushItem.ItemName + ShareItemData.ItemList.Count().ToString();
                                                EGPBushItem.ItemCode = "EGPBush";
                                                EGPBushItem.ItemNameType = DItemNameType.EGPBush;
                                                double MaxbushTY = BushArcList.Max(item => item.CenterPoint.CustomerPoint.Y);
                                                double MinbushTY = BushArcList.Min(item => item.CenterPoint.CustomerPoint.Y);
                                                double EGPBushLength = Math.Round(MaxbushTY - MinbushTY,2);
                                                //中托司Dim = 中托边Dim
                                                EGPBushItem.Dim = EGPItem.Dim;
                                                EGPBushItem.RealH = Convert.ToInt32(Math.Round(EGPBushLength, 0));
                                                EGPBushItem.BushSize = EGPItem.BushSize;
                                                EGPBushItem.HSplitInfo = SInfo;
                                                
                                                BoardSectionItem fpB = BList.Find(item => item.BoardCode.Equals("fpBoard"));
                                                BoardSectionItem epB = BList.Find(item => item.BoardCode.Equals("epBoard"));
                                                
                                                int fpIndex = BList.FindIndex(item => item.BoardCode.Equals("fpBoard"));
                                                int epIndex = BList.FindIndex(item => item.BoardCode.Equals("epBoard"));
                                                if (fpIndex != -1)
                                                    EGPBushItem.BushBoardList.Add(BList[fpIndex]);
                                                if (epIndex != -1)
                                                    EGPBushItem.BushTDBoard = BList[epIndex];

                                                int TempTheoryH = Convert.ToInt32(fpB.PlateThick + epB.PlateThick) - 5;
                                                EGPItem.RelScrewHoleList = EGPList;
                                                EGPBushItem.TheoryH = CU.GPLessThan200TheoryLRepRule(TempTheoryH);
                                                EGPBushItem.TheoryH = ComputedUtils.RepScrewItemLRule(EGPBushItem.TheoryH);
                                                EGPBushItem.RelScrewHoleList = EGPItem.RelScrewHoleList;
                                                EGPBushItem.ItemNum = EGPBushItem.RelScrewHoleList.Count;
                                                EGPBushItem.BushSize = RefEGPHole.BushSize;
                                                EGPBushItem.TD = RefEGPHole.TD;

                                                StandardEGP targetStandardParams = CU.ComputedSAboutEGPParams((int)EGPItem.Dim);
                                                EGPBushItem.InputBushSize = targetStandardParams.BushSize;
                                                EGPBushItem.InputBushTD = targetStandardParams.BushTD;
                                                EGPBushItem.InputBushTH = targetStandardParams.BushTH;

                                                tempEGPItemList.Add(EGPBushItem);
                                            }
                                        }
                                    }

                                }

                                EGPItem.ItemUID = EGPItem.ItemName + ShareItemData.ItemList.Count().ToString();
                                tempEGPItemList.Add(EGPItem);
                                DimArcScopeBList.Clear();
                                
                            }

                        }

                        //只支持2针板场景下 补EGP
                        Boolean fpBF = BList.FindAll(item => item.BoardCode.Equals("fpBoard")).ToList().Count() == 1;
                        Boolean epBF = BList.FindAll(item => item.BoardCode.Equals("epBoard")).ToList().Count() == 1;
                        if (fpBF && epBF)
                        {
                            RefHoleCenterSplitInfo SInfo = new RefHoleCenterSplitInfo();
                            SingleItem EGPItem = new SingleItem();
                            StandardEGP targetStandardParams = new StandardEGP();
                            Boolean HasNoEGPBushF = tempEGPItemList.FindIndex(item => item.ItemCode.Equals("EGPBush")) == -1;
                            Boolean HasNoEGPPinF = tempEGPItemList.FindIndex(item => item.ItemCode.Equals("EGPPin")) == -1;
                            if (HasNoEGPPinF)
                            {
                                EGPItem.ItemCode = "EGPPin";
                                EGPItem.ItemNameType = DItemNameType.EGPPin;
                                EGPItem.RealH = 0;
                                EGPItem.Dim = RefEGPHole.Dim;
                                targetStandardParams = CU.ComputedSAboutEGPParams((int)EGPItem.Dim);
                                EGPItem.Dim = targetStandardParams.Dimension;
                                EGPItem.InputTD = targetStandardParams.TD;
                                EGPItem.InputTH = targetStandardParams.TH;
                                BoardSectionItem tempLFB = BList.FindLast(item => item.BoardCode.Equals("fangtie"));
                                BoardSectionItem tempbpB = BList[bpBoardIndex];
                                double TY = tempLFB.OverheadLine.StartPoint.CustomerPoint.Y;
                                double BY = tempbpB.BottomLine.StartPoint.CustomerPoint.Y;
                                //中托边理论长度 Dim∮12-∮20，伸入B板（托板）15mm；>=∮25 伸入B板（托板）20mm
                                double MorePassL = 0;
                                if (12 <= EGPItem.Dim && EGPItem.Dim <= 20)
                                    MorePassL = 15;
                                if (EGPItem.Dim >= 25)
                                    MorePassL = 20;
                                EGPItem.TheoryH = Math.Round(TY - BY, 0) + MorePassL;
                                EGPItem.TheoryH = ComputedUtils.RepScrewItemLRule(EGPItem.TheoryH);
                                EGPItem.RelScrewHoleList = EGPList;
                                EGPItem.ItemNum = EGPItem.RelScrewHoleList.Count;
                                SInfo = TranRefCHoleData(EGPItem.ItemNameType, EGPItem.RelScrewHoleList);
                                EGPItem.HSplitInfo = SInfo;
                                EGPItem.ItemUID = EGPItem.ItemName + ShareItemData.ItemList.Count().ToString();
                                int LFIndex = BList.FindLastIndex(item => item.BoardCode.Equals("fangtie"));
                                int bpIndex = BList.FindIndex(item => item.BoardCode.Equals("bpBoard"));
                                int firstFIndex = BList.FindIndex(item => item.BoardCode.Equals("fangtie"));
                                if (firstFIndex != -1)
                                {
                                    if (firstFIndex - 1 >= 0)
                                        EGPItem.BlindHoleBoard = BList[firstFIndex - 1];
                                }
                                EGPItem.TDBoard = BList[BList.Count - 1];
                                tempEGPItemList.Add(EGPItem);
                            }
                            else
                            {
                                int EGPPinIndex = tempEGPItemList.FindIndex(item => item.ItemCode.Equals("EGPPin"));
                                if (EGPPinIndex != -1)
                                {
                                    EGPItem = tempEGPItemList[EGPPinIndex];
                                    SInfo = EGPItem.HSplitInfo;
                                    targetStandardParams = CU.ComputedSAboutEGPParams((int)EGPItem.Dim);
                                }
                            }
                            if (HasNoEGPBushF)
                            {
                                SingleItem EGPBushItem = new SingleItem();
                                EGPBushItem.HSplitInfo = SInfo;
                                EGPBushItem.ItemCode = "EGPBush";
                                EGPBushItem.ItemNameType = DItemNameType.EGPBush;
                                EGPBushItem.Dim = EGPItem.Dim;
                                BoardSectionItem fpB = BList.Find(item => item.BoardCode.Equals("fpBoard"));
                                BoardSectionItem epB = BList.Find(item => item.BoardCode.Equals("epBoard"));

                                //设置
                                int fpIndex = BList.FindIndex(item => item.BoardCode.Equals("fpBoard"));
                                int epIndex = BList.FindIndex(item => item.BoardCode.Equals("epBoard"));
                                if (fpIndex != -1)
                                    EGPBushItem.BushBoardList.Add(BList[fpIndex]);
                                if (epIndex != -1)
                                    EGPBushItem.BushTDBoard = BList[epIndex];
                                EGPBushItem.ItemUID = EGPBushItem.ItemName + ShareItemData.ItemList.Count().ToString();
                                EGPBushItem.RealH = 0;
                                //中托司理论长度:上针板+下针板-5，如果计算的尾数不是0或5，减少靠标准
                                int TempTheoryH = Convert.ToInt32(fpB.PlateThick + epB.PlateThick) - 5;
                                EGPBushItem.TheoryH = CU.GPLessThan200TheoryLRepRule(TempTheoryH);
                                EGPBushItem.TheoryH = ComputedUtils.RepScrewItemLRule(EGPBushItem.TheoryH);
                                EGPBushItem.BushSize = RefEGPHole.BushSize;
                                EGPBushItem.TD = RefEGPHole.TD;
                                EGPBushItem.InputBushSize = targetStandardParams.BushSize;
                                EGPBushItem.InputBushTD = targetStandardParams.BushTD;
                                EGPBushItem.InputBushTH = targetStandardParams.BushTH;
                                EGPBushItem.RelScrewHoleList = EGPItem.RelScrewHoleList;
                                EGPBushItem.ItemNum = EGPBushItem.RelScrewHoleList.Count;
                                tempEGPItemList.Add(EGPBushItem);
                            }
                        }
                    }
 
                }
                
                // Merge Assem Draw Same TheoryH About EGP Item
                if (tempEGPItemList.Count > 0)
                {
                    List<SingleItem> resList = new List<SingleItem>();
                    var egpItemGroup = tempEGPItemList.GroupBy(item => item.ItemNameType);
                    foreach (var Item in egpItemGroup)
                    {
                        List<SingleItem> ItemPartList = Item.ToList();
                        List<double> HList = ItemPartList.Select(item => item.TheoryH).Distinct().ToList();
                        for(int i = 0; i < HList.Count; i++)
                        {
                            SingleItem  temp = ItemPartList.Find(item => item.TheoryH == HList[i]);
                            resList.Add(temp);
                        }
                    }
                    if(resList.Count > 0)
                        ShareItemData.ItemList.AddRange(resList);
                }
            }
            catch (Exception)
            {
            }

        }

        //识别拉杆
        public static void RecognizeSP(Dictionary<double, List<MixedCAD_Line>> ItemTSLineYDic, 
            Dictionary<double, List<MixedCAD_Line>> AVLineYDic, List<MixedCAD_Arc> AArcList,List<MixedCAD_Line> ATranPolyList)
        {
            try
            {
                //组装图 拉杆零件参考中心X坐标 
                double? AVRefSplitX = null;
                double? AVRefCustomerX = null;
                //水口介子 最高点
                double? NoozzleMesonMaxY = null;
                //判断水口介子 默认没有水口介子
                Boolean NozzleMesonExit = false;
                List<ScrewHole> SPList = HoleCandidateShareData.SPScrewCList;
                ComputedUtils.SwitchTVHoleCoorType(SPList);
                //拉杆零件信息
                SingleItem SItem = new SingleItem();
                //拉杆集合
                List<CSingleItem> CTempSPList = new List<CSingleItem>();
                //全量 暂存 导套直径板信息
                List<BoardSectionItem> BushSizeBoardList = new List<BoardSectionItem>();
                //全量 暂存 导套托位全量信息(包含托位高度&&托位孔)
                List<PartBushTDArgItem> MergeBushTDInfoList = new List<PartBushTDArgItem>();
                //合适的单个导套托位信息
                List<SingleBushTDPartItem> SureBushTDPartList = new List<SingleBushTDPartItem>();
                //组装图上 拉杆 Dim&TD 竖线
                List<CSinglePartItem> SPItemDimAndTDVList = new List<CSinglePartItem>();
                //组装图上 拉杆 BushSize&BushTD 竖线
                List<CSinglePartItem> SPItemBushVList = new List<CSinglePartItem>();
                //与拉杆导套相关的板(大致范围)
                List<BoardSectionItem> AboutBSList = new List<BoardSectionItem>();
                //GP Scope Board
                List<BoardSectionItem> SPScopeBoardList = new List<BoardSectionItem>();
                //套 托位板 UID
                List<string> BushTDBoardUIDList = new List<string>();
                int mayRefBIndex = -1;
                //TD Bush 特征直线长度参考值 过滤长度过长 约A B 推 的1/5
                double? TDBushTDrefY = null;
                mayRefBIndex = CU.GetOneBoardIndex("aBoard");
                if (mayRefBIndex == -1)
                    mayRefBIndex = CU.GetOneBoardIndex("bBoard");
                if (mayRefBIndex == -1)
                    mayRefBIndex = CU.GetOneBoardIndex("stBoard");
                if (mayRefBIndex != -1)
                    TDBushTDrefY = AssemblyShareData.ASectionList[mayRefBIndex].PlateThick / 5;

                //在水口(面)板上找近似的 TD Dim(为了排除导柱的干扰 
                int cpBoardIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("cpBoard"));
                int bBoardIndex = AssemblyShareData.ASectionList.FindLastIndex(item => item.BoardCode.Equals("bBoard"));
                if (cpBoardIndex != -1 && bBoardIndex != -1)
                {
                    BoardSectionItem CPBS = AssemblyShareData.ASectionList[cpBoardIndex];
                    double cpBoardMaxY = Math.Round(CPBS.OverheadLine.UseStartPoint.Y, 0);
                    double cpBoardMinY = Math.Round(CPBS.BottomLine.UseStartPoint.Y, 0);
                    
                    List<MixedCAD_Line> CPPVLines = new List<MixedCAD_Line>();
                    List<double> cpBoardVLineKeys = AVLineYDic.Keys.ToList().FindAll(item => cpBoardMinY <= Math.Round(item, 0) 
                    && Math.Round(item, 0) <= cpBoardMaxY);
                    if (cpBoardVLineKeys != null)
                        cpBoardVLineKeys.ForEach(key => CPPVLines.AddRange(AVLineYDic[key]));
                    if(CPPVLines.Count > 0)
                    {
                        for (int i = 0; i < CPPVLines.Count - 1; i++)
                        {
                            for (int j = 1; j < CPPVLines.Count; j++)
                            {
                                if (j > i)
                                {
                                    for (int k = 0; k < SPList.Count; k++)
                                    {
                                        double TempDim = Math.Abs(CPPVLines[i].StartPoint.UsePoint.X - CPPVLines[j].StartPoint.UsePoint.X);
                                        double TwoLineSplitAgvCX = Math.Round((CPPVLines[i].StartPoint.UsePoint.X + CPPVLines[j].StartPoint.UsePoint.X) / 2, 1);
                                        double TwoLineCustomerAgvCX = Math.Round((CPPVLines[i].StartPoint.CustomerPoint.X + CPPVLines[j].StartPoint.CustomerPoint.X) / 2, 1);
                                        double TargetCenterX = Math.Round(SPList[k].CenterPoint.TransSplitPoint.X, 1);
                                        double LX = TargetCenterX - 50;
                                        double RX = TargetCenterX + 50;
                                        if (LX <= TwoLineSplitAgvCX && TwoLineSplitAgvCX <= RX)
                                        {
                                            CSinglePartItem SPItem = new CSinglePartItem();
                                            //TD
                                            if (SPList[k].TD - 1 - 0.01 <= TempDim && TempDim <= SPList[k].TD + 1 + 0.01)
                                            {
                                                SPItem.ItemType = ItemPartCodeType.TD;
                                                SPItem.LLine = CPPVLines[i];
                                                SPItem.RLine = CPPVLines[j];
                                                SPItem.XLength = TempDim;
                                                SPItem.YLength = Math.Round(Math.Abs(CPPVLines[i].StartPoint.CustomerPoint.Y - CPPVLines[i].EndPoint.CustomerPoint.Y), 0);
                                                SPItem.AVSplitCX = TwoLineSplitAgvCX;
                                                SPItem.AVCustomerCX = TwoLineCustomerAgvCX;
                                                SPItem.MatchScrewHole = SPList[k];
                                                SPItemDimAndTDVList.Add(SPItem);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    //filter TD
                    if(SPItemDimAndTDVList.Count > 0)
                        SPItemDimAndTDVList = SPItemDimAndTDVList.FindAll(item => CU.JudgeTwoYLineNoTooOverDis(item.LLine, item.RLine));

                    //Set AVRefSplitX
                    if (SPItemDimAndTDVList.Count > 0)
                    {
                        AVRefSplitX = CU.FindItemAVSplitCX(SPItemDimAndTDVList);
                        AVRefCustomerX = CU.FindItemAVCustomerCX(SPItemDimAndTDVList);
                    }

                    //根据 AVRealTDRefCorX 找出Dim 部位
                    if (CPPVLines.Count > 0 && AVRefSplitX != null && SPList.Count > 0)
                    {
                        double dimRefX = Math.Round((double)AVRefSplitX, 1);
                        ScrewHole refScrewHoleArg = SPList.First();
                        for (int i = 0; i < CPPVLines.Count - 1; i++)
                        {
                            for (int j = 1; j < CPPVLines.Count; j++)
                            {
                                if (j > i)
                                {
                                    double TempDim = Math.Abs(CPPVLines[i].StartPoint.UsePoint.X - CPPVLines[j].StartPoint.UsePoint.X);
                                    double TwoLineSplitAgvCX = Math.Round((CPPVLines[i].StartPoint.UsePoint.X + CPPVLines[j].StartPoint.UsePoint.X) / 2, 1);
                                    double LTDX = dimRefX - 0.5;
                                    double RTDX = dimRefX + 0.5;
                                    if (LTDX <= TwoLineSplitAgvCX && TwoLineSplitAgvCX <= RTDX)
                                    {
                                        CSinglePartItem SPItem = new CSinglePartItem();
                                        if (refScrewHoleArg.Dim - 0.02 <= TempDim && TempDim <= refScrewHoleArg.Dim + 0.02)
                                        {
                                            SPItem.ItemType = ItemPartCodeType.Dim;
                                            SPItem.LLine = CPPVLines[i];
                                            SPItem.RLine = CPPVLines[j];
                                            SPItem.XLength = TempDim;
                                            SPItem.YLength = Math.Round(Math.Abs(CPPVLines[i].Length), 0);
                                            SPItem.AVSplitCX = (double)AVRefSplitX;
                                            SPItem.AVCustomerCX = (double)AVRefCustomerX;
                                            SPItem.MatchScrewHole = refScrewHoleArg;
                                            SPItemDimAndTDVList.Add(SPItem);
                                        }

                                    }
                                }
                            }
                        }
                    }

                    if (SPItemDimAndTDVList.Count > 0)
                    {
                        List<CSinglePartItem> resList = new List<CSinglePartItem>();
                        resList.Add(SPItemDimAndTDVList[0]);
                        if (SPItemDimAndTDVList.Count > 1)
                        {
                            for (int i = 1; i < SPItemDimAndTDVList.Count; i++)
                            {
                                Boolean NoSameFlag = resList.FindIndex(item => CU.JudgeEqualItemPart(item, SPItemDimAndTDVList[i])) == -1;
                                if (NoSameFlag)
                                    resList.Add(SPItemDimAndTDVList[i]);
                            }
                        }
                        SPItemDimAndTDVList = resList;
                        if (SPItemDimAndTDVList.Count > 0)
                        {
                            var GroupByList = SPItemDimAndTDVList.GroupBy(item => item.TVCPX);
                            foreach (var Item in GroupByList)
                            {
                                List<CSinglePartItem> ItemPartList = Item.ToList();
                                CSingleItem CItem = new CSingleItem();
                                for (int i = 0; i < ItemPartList.Count; i++)
                                {
                                    CItem.CenterPoint.CustomerPoint.X = ItemPartList[i].AVCustomerCX;
                                    CItem.CenterPoint.TransSplitPoint.X = ItemPartList[i].AVSplitCX;
                                    CItem.MatchScrewHole = ItemPartList[i].MatchScrewHole;
                                    CItem.InfoList.Add(ItemPartList[i]);
                                }
                                CTempSPList.Add(CItem);
                            }
                        }
                    }

                    List<CSinglePartItem> ConformToDimList = SPItemDimAndTDVList.FindAll(item => item.ItemType == ItemPartCodeType.Dim);
                    if (ConformToDimList.Count > 0)
                    {
                        if(AVRefSplitX != null)
                        {
                            double aboutcpX = (double)AVRefSplitX;
                            if (FangtieShareData.HasLRF)
                            {
                                if (aboutcpX < FangtieShareData.FLXInfo.SplitX)
                                    FangtieShareData.SPAnotherFX = FangtieShareData.FLXInfo.SplitX;
                                if (aboutcpX > FangtieShareData.FRXInfo.SplitX)
                                    FangtieShareData.SPAnotherFX = FangtieShareData.FRXInfo.SplitX;
                            }
                            else
                            {
                                if (aboutcpX < FangtieShareData.NOFLXInfo.SplitX)
                                    FangtieShareData.SPAnotherFX = FangtieShareData.NOFLXInfo.SplitX;
                                if (aboutcpX > FangtieShareData.NOFRXInfo.SplitX)
                                    FangtieShareData.SPAnotherFX = FangtieShareData.NOFRXInfo.SplitX;
                            }
                            //先识别水口介子 水口介子参考的X坐标
                            double NozzleRefX = aboutcpX;
                            double SPDim = ConformToDimList.Select(item => item.XLength).Min();
                            SItem.Dim = SPDim;
                            List<BoardSectionItem> NMBSList = new List<BoardSectionItem>();
                            //在B板及B板以下找水口介子
                            if (AssemblyShareData.ASectionList.Count > bBoardIndex + 1)
                                NMBSList.AddRange(AssemblyShareData.ASectionList.GetRange(bBoardIndex, AssemblyShareData.ASectionList.Count - bBoardIndex));
                            NMBSList = NMBSList.FindAll(item => !item.BoardCode.Equals("fpBoard") && !item.BoardCode.Equals("epBoard")).ToList();
                            //反向 从下往上找
                            NMBSList = NMBSList.OrderByDescending(item => item.plateLineNo).ToList();
                            if (NMBSList.Count > 0)
                            {
                                //找介子
                                for (int z = 0; z < NMBSList.Count; z++)
                                {
                                    double NMBoardMaxY = Math.Round(NMBSList[z].OverheadLine.UseStartPoint.Y, 0);
                                    double NMBoardMinY = Math.Round(NMBSList[z].BottomLine.UseStartPoint.Y, 0);
                                    //竖 候选线
                                    List<MixedCAD_Line> NMEGPVLine = new List<MixedCAD_Line>();
                                    List<double> NMBoardVLineKeys = AVLineYDic.Keys.ToList().FindAll(item => NMBoardMinY <= Math.Round(item, 0)
                                    && Math.Round(item, 0) <= NMBoardMaxY);
                                    if (NMBoardVLineKeys != null)
                                        NMBoardVLineKeys.ForEach(key => NMEGPVLine.AddRange(AVLineYDic[key]));
                                    NMEGPVLine = NMEGPVLine.FindAll(item => CU.JudgeEGPBLine(item.StartPoint.UsePoint.X));
                                    if (NMEGPVLine.Count > 0)
                                    {
                                        for (int i = 0; i < NMEGPVLine.Count; i++)
                                        {
                                            for (int j = 1; j < NMEGPVLine.Count; j++)
                                            {
                                                if (j > i)
                                                {
                                                    double TempDim = Math.Abs(NMEGPVLine[i].StartPoint.UsePoint.X - NMEGPVLine[j].StartPoint.UsePoint.X);
                                                    //近似中心对称 计算误差在+- 0.2
                                                    double TwoLineSplitAgvCX = Math.Round((NMEGPVLine[i].StartPoint.UsePoint.X + NMEGPVLine[j].StartPoint.UsePoint.X) / 2, 1);
                                                    if (NozzleRefX - 0.2 <= TwoLineSplitAgvCX && TwoLineSplitAgvCX <= NozzleRefX + 0.2)
                                                    {
                                                        //水口介子
                                                        if (SPDim + 4 <= TempDim && TempDim <= SPDim + 10)
                                                        {
                                                            NoozzleMesonMaxY = NMEGPVLine[i].StartPoint.CustomerPoint.Y > NMEGPVLine[j].StartPoint.CustomerPoint.Y 
                                                                ? NMEGPVLine[i].StartPoint.CustomerPoint.Y : NMEGPVLine[j].StartPoint.CustomerPoint.Y;
                                                            NozzleMesonExit = true;
                                                            goto ContinueNozzlelogic;
                                                        }

                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                                ContinueNozzlelogic:
                                {
                                    //从多段线的信息中接着找
                                    if (!NozzleMesonExit)
                                    {
                                        List<MixedCAD_Line> YWithPolyList = ATranPolyList.FindAll(item => item.LineType == CADLineType.YDirLine).ToList();
                                        if (YWithPolyList.Count > 0)
                                        {
                                            for (int z = 0; z < NMBSList.Count; z++)
                                            {
                                                double nmbMaxY = NMBSList[z].OverheadLine.StartPoint.CustomerPoint.Y;
                                                double nmbMinY = NMBSList[z].BottomLine.StartPoint.CustomerPoint.Y;
                                                List<MixedCAD_Line> NMYWithPolyList = YWithPolyList.FindAll(item => nmbMinY <= item.StartPoint.CustomerPoint.Y
                                                && item.StartPoint.CustomerPoint.Y <= nmbMaxY);
                                                if (NMYWithPolyList.Count > 0)
                                                {
                                                    for (int i = 0; i < NMYWithPolyList.Count; i++)
                                                    {
                                                        for (int j = 1; j < NMYWithPolyList.Count; j++)
                                                        {
                                                            if (j > i)
                                                            {
                                                                double TempDim = Math.Abs(NMYWithPolyList[i].StartPoint.CustomerPoint.X - NMYWithPolyList[j].StartPoint.CustomerPoint.X);
                                                                //近似中心对称 计算误差 +- 0.2
                                                                double TwoLineSplitAgvCX = Math.Round((NMYWithPolyList[i].StartPoint.CustomerPoint.X + NMYWithPolyList[j].StartPoint.CustomerPoint.X) / 2, 1);
                                                                if (NozzleRefX - 0.2 <= TwoLineSplitAgvCX && TwoLineSplitAgvCX <= NozzleRefX + 0.2)
                                                                {
                                                                    //水口介子
                                                                    if (SPDim + 4 <= TempDim && TempDim <= SPDim + 10)
                                                                    {
                                                                        NoozzleMesonMaxY = NMYWithPolyList[i].StartPoint.CustomerPoint.Y > NMYWithPolyList[j].StartPoint.CustomerPoint.Y ?
                                                                            NMYWithPolyList[i].StartPoint.CustomerPoint.Y : NMYWithPolyList[j].StartPoint.CustomerPoint.Y;
                                                                        NozzleMesonExit = true;
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            
                            }

                        }
                        
                    }

                    //收集导套外径 导套托位 等信息
                    if (SPItemDimAndTDVList.Count > 0)
                    {
                        //确定查找范围
                        int rspBoardIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("rspBoard"));
                        int? lastBoardIndex = null;
                        //有介子 推板及推板一下 不装套
                        if (NozzleMesonExit)
                        {
                            lastBoardIndex = AssemblyShareData.ASectionList.FindLastIndex(item => item.BoardCode.Equals("stBoard"));
                            if(lastBoardIndex == -1)
                                lastBoardIndex = AssemblyShareData.ASectionList.FindLastIndex(item => item.BoardCode.Equals("aBoard"));
                        }
                        else 
                        {
                            Boolean fangtieF = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("fangtie")) != -1;
                            //没介子 有方铁 推板及以下 不装套
                            if (fangtieF)
                                lastBoardIndex = AssemblyShareData.ASectionList.FindLastIndex(item => item.BoardCode.Equals("stBoard"));
                            //没介子 且没方铁情况下 整套模找套
                            else
                                lastBoardIndex = AssemblyShareData.ASectionList.Count - 1;
                        }
                        if(lastBoardIndex != -1)
                        {
                            AboutBSList = AssemblyShareData.ASectionList.GetRange(rspBoardIndex, (int)lastBoardIndex - rspBoardIndex + 1);
                            if (AVRefSplitX != null && AboutBSList.Count > 0)
                            {
                                //拉杆导套/导套托位
                                List<MixedCAD_Line> BushTDGPVLines = new List<MixedCAD_Line>();
                                for (int z = 0; z < AboutBSList.Count; z++)
                                {
                                    double BoardMaxY = Math.Round(AboutBSList[z].OverheadLine.UseStartPoint.Y, 0);
                                    double BoardMinY = Math.Round(AboutBSList[z].BottomLine.UseStartPoint.Y, 0);
                                    List<double> BoardVLineKeys = AVLineYDic.Keys.ToList().FindAll(item => BoardMinY <= Math.Round(item, 0) 
                                    && Math.Round(item, 0) <= BoardMaxY);
                                    if (BoardVLineKeys != null)
                                        BoardVLineKeys.ForEach(key => BushTDGPVLines.AddRange(AVLineYDic[key]));
                                }
                                //收集
                                if (BushTDGPVLines.Count > 0)
                                {
                                    double SPAVRealRefCX = (double)AVRefSplitX;
                                    ScrewHole refScrewHole = SPList[0];
                                    for (int i = 0; i < BushTDGPVLines.Count - 1; i++)
                                    {
                                        for (int j = 1; j < BushTDGPVLines.Count; j++)
                                        {
                                            if (j > i)
                                            {
                                                double TempDim = Math.Abs(BushTDGPVLines[i].StartPoint.TransSplitPoint.X - BushTDGPVLines[j].StartPoint.TransSplitPoint.X);
                                                double TwoLineSplitAgvCX = Math.Round((BushTDGPVLines[i].StartPoint.TransSplitPoint.X + BushTDGPVLines[j].StartPoint.TransSplitPoint.X) / 2, 1);
                                                double LX = TwoLineSplitAgvCX - 2;
                                                double RX = TwoLineSplitAgvCX + 2;

                                                Boolean satF = LX <= SPAVRealRefCX && SPAVRealRefCX <= RX;
                                                if (satF)
                                                {
                                                    CSinglePartItem SPItem = new CSinglePartItem();
                                                    if (refScrewHole.BushSize - 2 -0.01 <= TempDim && TempDim <= refScrewHole.BushSize + 2 + 0.01)
                                                    {
                                                        //BushSize
                                                        SPItem.ItemType = ItemPartCodeType.BushSize;
                                                        SPItem.LLine = BushTDGPVLines[i];
                                                        SPItem.RLine = BushTDGPVLines[j];
                                                        SPItem.XLength = TempDim;
                                                        SPItem.YLength = Math.Round(Math.Abs(BushTDGPVLines[i].StartPoint.CustomerPoint.Y - BushTDGPVLines[i].EndPoint.CustomerPoint.Y), 0);
                                                        SPItem.AVSplitCX = SPAVRealRefCX;
                                                        SPItem.MatchScrewHole = refScrewHole;
                                                        SPItemBushVList.Add(SPItem);
                                                    }
                                                    //BushTD +- 2
                                                    if (refScrewHole.BushTD - 2 - 0.01 <= TempDim && TempDim <= refScrewHole.BushTD + 2 + 0.01)
                                                    {
                                                        //BushTD
                                                        SPItem.ItemType = ItemPartCodeType.BushTD;
                                                        SPItem.LLine = BushTDGPVLines[i];
                                                        SPItem.RLine = BushTDGPVLines[j];
                                                        SPItem.XLength = TempDim;
                                                        SPItem.YLength = Math.Round(Math.Abs(BushTDGPVLines[i].StartPoint.CustomerPoint.Y - BushTDGPVLines[i].EndPoint.CustomerPoint.Y), 0);
                                                        SPItem.AVSplitCX = SPAVRealRefCX;
                                                        SPItem.MatchScrewHole = refScrewHole;
                                                        SPItemBushVList.Add(SPItem);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                            }
                        }
                    } 

                    //收集导套托位相关的数据
                    List<CSinglePartItem> CRBushTDList = SPItemBushVList.FindAll(item => item.ItemType == ItemPartCodeType.BushTD);
                    //导套托位横值信息
                    List<double> BushTDValueList = new List<double>();
                    if (CRBushTDList.Count > 0)
                    {
                        CRBushTDList = CRBushTDList.Distinct(new CSinglePartItemComparer()).ToList();
                        CRBushTDList = CRBushTDList.FindAll(item => CU.JudgeTwoYLineNoTooOverDis(item.LLine, item.RLine));
                        SPItemBushVList = SPItemBushVList.FindAll(item => !(item.ItemType == ItemPartCodeType.BushTD));
                        SPItemBushVList.AddRange(CRBushTDList);
                        if (CRBushTDList.Count > 0)
                            BushTDValueList = CRBushTDList.Select(item => item.XLength).Distinct().ToList();
                    }

                    //Merge BushSize & BushTD Info
                    if (SPItemBushVList.Count > 0)
                    {
                        //收集导套托位相关的数据
                        List<CSinglePartItem> tempCRBushTDList = SPItemBushVList.FindAll(item => item.ItemType == ItemPartCodeType.BushTD);
                        //粗粒度去重
                        if (tempCRBushTDList.Count > 0)
                        {
                            List<CSinglePartItem> resList = new List<CSinglePartItem>();
                            resList.Add(tempCRBushTDList[0]);
                            if (tempCRBushTDList.Count > 1)
                            {
                                for (int i = 1; i < tempCRBushTDList.Count; i++)
                                {
                                    Boolean NoSameFlag = resList.FindIndex(item => CU.JudgeRepeatBushTDPart(item, tempCRBushTDList[i])) == -1;
                                    if (NoSameFlag)
                                        resList.Add(tempCRBushTDList[i]);
                                }
                            }
                            CRBushTDList = resList;
                            for (int i = 0; i < CRBushTDList.Count; i++)
                            {
                                double LSY = CRBushTDList[i].LLine.StartPoint.CustomerPoint.Y;
                                double LEY = CRBushTDList[i].LLine.EndPoint.CustomerPoint.Y;
                                double RSY = CRBushTDList[i].RLine.StartPoint.CustomerPoint.Y;
                                double REY = CRBushTDList[i].RLine.EndPoint.CustomerPoint.Y;
                                //概率大一点
                                double TY = LSY < RSY ? LSY : RSY;
                                double BY = LEY > REY ? LEY : REY;
                                int BushTDIndex = AboutBSList.FindIndex(Item => TY <= Item.OverheadLine.StartPoint.CustomerPoint.Y
                                && Item.BottomLine.StartPoint.CustomerPoint.Y <= BY);
                                if (BushTDIndex != -1)
                                {
                                    SingleBushTDPartItem TempBushTDPart = new SingleBushTDPartItem();
                                    TempBushTDPart.XLength = CRBushTDList[i].XLength;
                                    //比较平均值 确定导套托位安装方式
                                    TempBushTDPart.BushTDBoard = AboutBSList[BushTDIndex];
                                    double BTDOY = TempBushTDPart.BushTDBoard.OverheadLine.StartPoint.CustomerPoint.Y;
                                    double BTDBY = TempBushTDPart.BushTDBoard.BottomLine.StartPoint.CustomerPoint.Y;
                                    double TempBushTDH = Math.Round(TY - BY, 0);
                                    TempBushTDPart.H = TempBushTDH;
                                    double AveBH = (BTDOY + BTDBY) / 2;
                                    double AveBushTDH = (TY + BY) / 2;
                                    if (AveBH < AveBushTDH)
                                        TempBushTDPart.BushTDPosType = InBoardPosType.BoardUp;
                                    else
                                        TempBushTDPart.BushTDPosType = InBoardPosType.BoardDown;
                                    SureBushTDPartList.Add(TempBushTDPart);
                                }
                            }
                            //去重 套孔H和套H不一定一致
                            if (SureBushTDPartList.Count > 0)
                            {
                                List<SingleBushTDPartItem> TCbushTDPList = new List<SingleBushTDPartItem>();
                                TCbushTDPList.Add(SureBushTDPartList[0]);
                                if (SureBushTDPartList.Count > 1)
                                {
                                    for (int i = 1; i < SureBushTDPartList.Count; i++)
                                    {
                                        Boolean F = TCbushTDPList.FindIndex(item => CU.JudgeSameBushTDPartInfo(item, SureBushTDPartList[i])) == -1;
                                        if (F)
                                            TCbushTDPList.Add(SureBushTDPartList[i]);
                                    }
                                }
                                SureBushTDPartList = TCbushTDPList;
                                SureBushTDPartList = SureBushTDPartList.Distinct(new SingleBushTDPartItemComparer()).ToList();
                            }
                        }
                        MergeBushTDInfoList = CU.MergePartBushTDInfo(SureBushTDPartList);
                        
                        if (MergeBushTDInfoList.Count > 0)
                            BushTDBoardUIDList = MergeBushTDInfoList.Select(item => item.BushTDBoard.BoardUID).ToList();
                        //收集导套直径相关的数据
                        List<CSinglePartItem> CRBushSizeList = SPItemBushVList.FindAll(item => item.ItemType == ItemPartCodeType.BushSize);
                        //去重
                        if (CRBushSizeList.Count > 0)
                        {
                            List<CSinglePartItem> resList = new List<CSinglePartItem>();
                            resList.Add(CRBushSizeList[0]);
                            if (CRBushSizeList.Count > 1)
                            {
                                for (int i = 1; i < CRBushSizeList.Count; i++)
                                {
                                    Boolean NoSameFlag = resList.FindIndex(item => CU.JudgeRepeatBushTDPart(item, CRBushSizeList[i])) == -1;
                                    if (NoSameFlag)
                                        resList.Add(CRBushSizeList[i]);
                                }
                            }
                            CRBushSizeList = resList;
                            //导套直径线段有可能连续穿过两块及两块以上的板 TO EDIT 画法不标准 导致导套直径线段超出板件
                            for (int i = 0; i < CRBushSizeList.Count; i++)
                            {
                                double LSY = CRBushSizeList[i].LLine.StartPoint.CustomerPoint.Y;
                                double LEY = CRBushSizeList[i].LLine.EndPoint.CustomerPoint.Y;
                                double RSY = CRBushSizeList[i].RLine.StartPoint.CustomerPoint.Y;
                                double REY = CRBushSizeList[i].RLine.EndPoint.CustomerPoint.Y;
                                double TY = LSY < RSY ? LSY : RSY;
                                double BY = LEY > REY ? LEY : REY;
                                //区间
                                int FirstBoardIndex = AboutBSList.FindLastIndex(Item => TY <= Item.OverheadLine.StartPoint.CustomerPoint.Y);
                                int SecondBoardIndex = AboutBSList.FindIndex(Item => Item.BottomLine.StartPoint.CustomerPoint.Y <= BY);
                                if (FirstBoardIndex != -1 && SecondBoardIndex != -1 && SecondBoardIndex >= FirstBoardIndex)
                                {
                                    List<BoardSectionItem> TempAreaBList = AboutBSList.GetRange(FirstBoardIndex, SecondBoardIndex - FirstBoardIndex + 1);
                                    if (TempAreaBList.Count > 0)
                                        BushSizeBoardList.AddRange(TempAreaBList);
                                }
                            }
                        }
                        if (BushSizeBoardList.Count > 0)
                            BushSizeBoardList = BushSizeBoardList.Distinct().ToList();
                        //导套托位板有可能包含于导套外径板
                        if (MergeBushTDInfoList.Count > 0 && BushSizeBoardList.Count > 0)
                        {
                            List<string> BoardUIDList = MergeBushTDInfoList.Select(item => item.BushTDBoard.BoardUID).ToList();
                            if (BoardUIDList.Count > 0)
                            {
                                List<BoardSectionItem> depTempList = new List<BoardSectionItem>();
                                for (int depi = 0; depi < BoardUIDList.Count; depi++)
                                {
                                    int depIndex = BushSizeBoardList.FindIndex(item => item.BoardUID.Equals(BoardUIDList[depi]));
                                    if (depIndex != -1)
                                        BushSizeBoardList.RemoveAt(depIndex);
                                }
                            }
                        }  
                    }

                    //开始整理 全部信息
                    if (SPItemDimAndTDVList.Count > 0)
                    {
                        CTempSPList = CTempSPList.FindAll(item => item.InfoList.Select(Info => Info.ItemType).ToList().Contains(ItemPartCodeType.Dim));
                        if (CTempSPList.Count > 0)
                        {
                            double SPDim = CTempSPList[0].InfoList.FindAll(item => item.ItemType == ItemPartCodeType.Dim).Select(item => item.XLength).Min();
                            if (NozzleMesonExit)
                            {
                                SItem.ItemCode = "SupportPin";
                                SItem.AssembleCenterPointX = (double)AVRefSplitX;
                                SItem.AVCustomerCX = (double)AVRefCustomerX;
                                //有水口介子叫拉杆
                                SItem.ItemNameType = DItemNameType.SupportPin;
                                double BeginY = AssemblyShareData.ASectionList[0].OverheadLine.StartPoint.CustomerPoint.Y;
                                //拉杆长度 = 第一块板 到 水口介子的高度
                                double PRH = Math.Round(BeginY - (double)NoozzleMesonMaxY, 0);
                                SItem.PeakY = BeginY;
                                SItem.NadirY = (double)NoozzleMesonMaxY;
                                List<BoardSectionItem> NoepfpBoardList = AssemblyShareData.ASectionList.FindAll(item =>
                                !item.BoardCode.Equals("epBoard") && !item.BoardCode.Equals("fpBoard"));
                                double ThickSum = 0;
                                int EndBoardIndex = 0;
                                for (int i = 0; i < NoepfpBoardList.Count; i++)
                                {
                                    ThickSum += NoepfpBoardList[i].PlateThick;
                                    EndBoardIndex = i;
                                    if (PRH <= ThickSum)
                                        break;
                                }
                                SItem.RealH = Convert.ToInt32(Math.Round(PRH, 0));
                                SItem.TheoryH = CU.SPTheoryLRepRule(SItem.RealH);
                            }
                            else
                            {
                                double RefCX = (double)AVRefSplitX;
                                SItem.AssembleCenterPointX = (double)AVRefSplitX;
                                SItem.ItemCode = "NoNozzleMesonSupportPin";
                                //没水口介子
                                SItem.ItemNameType = DItemNameType.NoNozzleMesonSupportPin;
                                SItem.PRTransitionGPFlag = true;
                                //横 候选线
                                List<MixedCAD_Line> TSSPLines = new List<MixedCAD_Line>();
                                //所有 直径相关横线
                                List<MixedCAD_Line> CDimTSLineList = new List<MixedCAD_Line>();
                                List<BoardSectionItem> LRPBSList = new List<BoardSectionItem>(AssemblyShareData.ASectionList);
                                double MoldMaxY = LRPBSList.Max(Item => Item.OverheadLine.StartPoint.TransSplitPoint.Y);
                                double MoldMinY = LRPBSList.Min(Item => Item.BottomLine.StartPoint.TransSplitPoint.Y);

                                List<double> BoardTSLineKeys = ItemTSLineYDic.Keys.ToList().FindAll(item => MoldMinY <= Math.Round(item, 0) 
                                && Math.Round(item, 0) <= MoldMaxY);
                                if (BoardTSLineKeys != null)
                                    BoardTSLineKeys.ForEach(key => TSSPLines.AddRange(ItemTSLineYDic[key]));

                                //比较吻合拉杆的圆弧(候选集)
                                List<MixedCAD_Arc> CandidateArcList = AArcList;
                                if (FangtieShareData.HasLRF)
                                {
                                    if (FangtieShareData.SPAnotherFX == FangtieShareData.FLXInfo.SplitX)
                                    {
                                        CandidateArcList = CandidateArcList.FindAll(item => item.StartPoint.TransSplitPoint.X < FangtieShareData.SPAnotherFX);
                                        TSSPLines = TSSPLines.FindAll(item => item.StartPoint.TransSplitPoint.X < FangtieShareData.SPAnotherFX);
                                    }
                                    if (FangtieShareData.SPAnotherFX == FangtieShareData.FRXInfo.SplitX)
                                    {
                                        CandidateArcList = CandidateArcList.FindAll(item => item.StartPoint.TransSplitPoint.X > FangtieShareData.SPAnotherFX);
                                        TSSPLines = TSSPLines.FindAll(item => item.StartPoint.TransSplitPoint.X > FangtieShareData.SPAnotherFX);
                                    }
                                }
                                else
                                {
                                    if (FangtieShareData.SPAnotherFX == FangtieShareData.NOFLXInfo.SplitX)
                                    {
                                        CandidateArcList = CandidateArcList.FindAll(item => item.StartPoint.TransSplitPoint.X < FangtieShareData.SPAnotherFX);
                                        TSSPLines = TSSPLines.FindAll(item => item.StartPoint.TransSplitPoint.X < FangtieShareData.SPAnotherFX);
                                    }
                                    if (FangtieShareData.SPAnotherFX == FangtieShareData.NOFRXInfo.SplitX)
                                    {
                                        CandidateArcList = CandidateArcList.FindAll(item => item.StartPoint.TransSplitPoint.X > FangtieShareData.SPAnotherFX);
                                        TSSPLines = TSSPLines.FindAll(item => item.StartPoint.TransSplitPoint.X > FangtieShareData.SPAnotherFX);
                                    }
                                }

                                for (int l = 0; l < TSSPLines.Count; l++)
                                {
                                    double TTLineCX = Math.Round((TSSPLines[l].StartPoint.TransSplitPoint.X + TSSPLines[l].EndPoint.TransSplitPoint.X) / 2, 1);
                                    if (RefCX - 0.2 < TTLineCX && TTLineCX < RefCX + 0.2)
                                    {
                                        double TempTSXLength = Math.Round(TSSPLines[l].Length, 1);
                                        //防止用户画图不标准
                                        if (SPDim - 0.5 <= TempTSXLength && TempTSXLength <= SPDim + 0.5)
                                            CDimTSLineList.Add(TSSPLines[l]);
                                    }
                                }
                                if (CDimTSLineList.Count > 0)
                                    {
                                        double MinY = CDimTSLineList.Select(item => item.StartPoint.CustomerPoint.Y).Min();
                                        MixedCAD_Line minItem = CDimTSLineList.Find(item => item.StartPoint.CustomerPoint.Y == MinY);
                                        //拉杆尽头的圆弧
                                        List<MixedCAD_Arc> ConnArcList = CandidateArcList.FindAll(item => CU.JudgeArcCenterInLine(minItem, item));
                                        if (ConnArcList.Count > 0)
                                        {
                                            double MinEPY = ConnArcList.Min(item => item.EndPoint.CustomerPoint.Y);
                                            double MinSPY = ConnArcList.Min(item => item.StartPoint.CustomerPoint.Y);
                                            MixedCAD_Arc LastEndPArc = ConnArcList.FindLast(item => item.EndPoint.CustomerPoint.Y == MinEPY);
                                            MixedCAD_Arc LastStartPArc = ConnArcList.FindLast(item => item.StartPoint.CustomerPoint.Y == MinSPY);
                                            MixedCAD_Point StartRPArcPoint = LastStartPArc.StartPoint.CustomerPoint.Y < LastStartPArc.EndPoint.CustomerPoint.Y ? 
                                            LastStartPArc.StartPoint : LastStartPArc.EndPoint;
                                            MixedCAD_Point EndRPArcPoint = LastEndPArc.StartPoint.CustomerPoint.Y < LastEndPArc.EndPoint.CustomerPoint.Y ? 
                                             LastEndPArc.StartPoint : LastEndPArc.EndPoint;
                                            double MinArcY = StartRPArcPoint.CustomerPoint.Y < EndRPArcPoint.CustomerPoint.Y ? StartRPArcPoint.CustomerPoint.Y : EndRPArcPoint.CustomerPoint.Y;
                                            double BeginY = AssemblyShareData.ASectionList[0].OverheadLine.StartPoint.CustomerPoint.Y;
                                            double ThickSum = 0;
                                            //拉杆长度 = 第一块板 到 最底部 圆弧最低点
                                            double PRH = Math.Round(BeginY - MinArcY, 0);
                                            SItem.PeakY = BeginY;
                                            SItem.NadirY = MinArcY;
                                            List<BoardSectionItem> NoepfpBoardList = AssemblyShareData.ASectionList.FindAll(item =>
                                            !item.BoardCode.Equals("epBoard") && !item.BoardCode.Equals("fpBoard"));
                                            int EndBoardIndex = 0;
                                            for (int i = 0; i < NoepfpBoardList.Count; i++)
                                            {
                                                ThickSum += NoepfpBoardList[i].PlateThick;
                                                EndBoardIndex = i;
                                                if (PRH <= ThickSum)
                                                    break;
                                            }
                                            SItem.RealH = Convert.ToInt32(Math.Round(PRH, 0));
                                            SItem.TheoryH = CU.SPTheoryLRepRule(SItem.RealH);
                                        }
                                    }
                            }
                            SItem.TDBoard = AssemblyShareData.ASectionList.Find(item => item.BoardCode.Equals("cpBoard"));
                            //整个拉杆所在板
                            int BeginBIndex = AssemblyShareData.ASectionList.FindLastIndex(item => Math.Round(item.OverheadLine.StartPoint.CustomerPoint.Y)
                            >= Math.Round((double)SItem.PeakY, 0));
                            int EndBIndex = AssemblyShareData.ASectionList.FindIndex(item => Math.Round(item.BottomLine.StartPoint.CustomerPoint.Y) 
                            <= Math.Round((double)SItem.NadirY, 0));
                            if (BeginBIndex != -1 && EndBIndex != -1)
                            {
                                int BIndex = BeginBIndex < EndBIndex ? BeginBIndex : EndBIndex;
                                int EIndex = BeginBIndex > EndBIndex ? BeginBIndex : EndBIndex;
                                SPScopeBoardList = AssemblyShareData.ASectionList.GetRange(BIndex, EIndex - BIndex + 1);
                            }
                            //模架只会出现一种类型的拉杆 只考虑第一个数据就行
                            CSingleItem FirstSPItem = CTempSPList[0];
                            //关联孔和零件数量
                            FirstSPItem.RelScrewHoleList = SPList.FindAll(item =>
                            (FirstSPItem.MatchScrewHole.Dim - 0.01 <= item.Dim && item.Dim <= FirstSPItem.MatchScrewHole.Dim + 0.01)
                            &&
                            (FirstSPItem.MatchScrewHole.TD - 0.01 <= item.TD && item.TD <= FirstSPItem.MatchScrewHole.TD + 0.01));
                            SItem.RelScrewHoleList = FirstSPItem.RelScrewHoleList;
                            SItem.ItemNum = SItem.RelScrewHoleList.Count;
                            if (FirstSPItem.InfoList.Count > 0)
                            {
                                SPItemDimAndTDVList.Clear();
                                //Args T Value(Bush TD Dim)
                                List<double> GPXLengthList = FirstSPItem.InfoList.Select(item => item.XLength).Distinct().OrderBy(item => item).ToList();
                                //Stand
                                List<int> StandradDimList = StandardShareScopeItemParam.GPSScrewDimList;
                                //Dim Info
                                CSinglePartItem DimPartItem = FirstSPItem.InfoList.Find(item => item.ItemType == ItemPartCodeType.Dim);

                                if (DimPartItem != null && StandradDimList.Count > 0)
                                {
                                    int CDim = StandradDimList.Find(item => item - 0.02 <= DimPartItem.XLength && DimPartItem.XLength <= item + 0.02);
                                    //this Size Full parameter
                                    StandardGPSP ScrewItem = ParamsConfigData.StandardGPList.Find(item => item.Dimension == CDim);
                                    if (ScrewItem != null)
                                    {
                                            // Default Install Type
                                            SItem.TDPosType = InBoardPosType.BoardUp;
                                            SItem.TVCPX = (double)AVRefSplitX;
                                            SItem.Dim = Math.Round(DimPartItem.XLength, 0);
                                            SItem.TD = (int)Math.Round(GPXLengthList.Find(item => ScrewItem.TD - 1 <= item && item <= ScrewItem.TD + 1), 0);
                                            List<double> BushTDXValueList = MergeBushTDInfoList.Select(item => item.XLength).Distinct().ToList();
                                            if (BushTDXValueList.Count > 0)
                                            {
                                                double nearBushTDDif = BushTDXValueList.Max(item => Math.Abs(item - ScrewItem.BushTD));
                                                double bestbushTDValue = BushTDValueList.Find(item => Math.Abs(item - ScrewItem.BushTD) == nearBushTDDif);
                                                bestbushTDValue = Math.Round(bestbushTDValue, 0);
                                                SItem.BushTD = (int)bestbushTDValue;
                                            }
                                            List<CSinglePartItem> CRBushSizeList = SPItemBushVList.FindAll(item => item.ItemType == ItemPartCodeType.BushSize);
                                            List<double> BushSizeXValueList = CRBushSizeList.Select(item => item.XLength).Distinct().ToList();
                                            if (BushSizeXValueList.Count > 0)
                                            {
                                                double nearBushSizeDif = BushSizeXValueList.Min(item => Math.Abs(item - ScrewItem.BushSize));
                                                SItem.BushSize = (int)BushSizeXValueList.Find(item => Math.Abs(item - ScrewItem.BushSize) == nearBushSizeDif);
                                            }
                                            List<double> TDDataList = FirstSPItem.InfoList.FindAll(item => item.ItemType == ItemPartCodeType.TD).Select(item => item.YLength).ToList();
                                            if (TDDataList.Count > 0)
                                                SItem.TH = Convert.ToDecimal(TDDataList.Distinct().Max());

                                            RefHoleCenterSplitInfo SInfo = TranRefCHoleData(SItem.ItemNameType, SItem.RelScrewHoleList);
                                            SItem.HSplitInfo = SInfo;

                                            //Add Meson & MesonScrew
                                            if (NozzleMesonExit)
                                            {
                                                SingleItem MisItem = RepMesonSpe(SItem.Dim);
                                                MisItem.ItemCode = "Meson";
                                                MisItem.ItemNum = SItem.ItemNum;
                                                ShareItemData.ItemList.Add(MisItem);
                                                SingleItem MisScrewItem = RepMesonScrewSpe(SItem.Dim);
                                                MisScrewItem.ItemCode = "MesonScrew";
                                                MisScrewItem.ItemNum = SItem.ItemNum;
                                                ShareItemData.ItemList.Add(MisScrewItem);
                                            }
                                            //SP Under stBoard Not Assem Bush stBoard ~ spBoard ASSEM bush 
                                            //Continue Collection SP Bush Info SP Bush Board Area 
                                            double DimLX = SItem.TVCPX - SItem.Dim / 2;
                                            double DimRX = SItem.TVCPX + SItem.Dim / 2;
                                            double BushLX = SItem.TVCPX - SItem.BushSize / 2;
                                            double BushRX = SItem.TVCPX + SItem.BushSize / 2;
                                            List<BoardAboutBushInfo> AboutBushUIDList = new List<BoardAboutBushInfo>();
                                            //Collection
                                            if (MergeBushTDInfoList.Count > 0)
                                            {
                                                for (int tdi = 0; tdi < MergeBushTDInfoList.Count; tdi++)
                                                {
                                                    BoardAboutBushInfo BoardBushInfo = new BoardAboutBushInfo();
                                                    BoardBushInfo.BoardUID = MergeBushTDInfoList[tdi].BushTDBoard.BoardUID;
                                                    BoardBushInfo.BushType = BushBoardType.B;
                                                    AboutBushUIDList.Add(BoardBushInfo);
                                                }
                                            }
                                            if (BushSizeBoardList.Count > 0)
                                            {
                                                BushSizeBoardList = BushSizeBoardList.OrderBy(item => item.plateLineNo).ToList();
                                                for (int bsi = 0; bsi < BushSizeBoardList.Count; bsi++)
                                                {
                                                    BoardAboutBushInfo BoardBushInfo = new BoardAboutBushInfo();
                                                    BoardBushInfo.BoardUID = BushSizeBoardList[bsi].BoardUID;
                                                    BoardBushInfo.BushType = BushBoardType.A;
                                                    AboutBushUIDList.Add(BoardBushInfo);
                                                }
                                            }
                                            AboutBushUIDList = AboutBushUIDList.Distinct().ToList();
                                            if (AboutBushUIDList.Count > 0)
                                            {
                                                List<BoardSectionItem> AboutBushBList = AboutBSList.FindAll(item => AboutBushUIDList.Select(UIDItem => UIDItem.BoardUID).Contains(item.BoardUID));
                                                if (AboutBushBList.Count > 0 && AArcList.Count > 0)
                                                {
                                                    double BushTY = AboutBushBList.Max(item => item.OverheadLine.StartPoint.CustomerPoint.Y);
                                                    double BushBY = AboutBushBList.Min(item => item.BottomLine.StartPoint.CustomerPoint.Y);
                                                    AboutBushBList = AboutBushBList.OrderBy(item => item.plateLineNo).ToList();
                                                    //以板UID为KEY 各板的导套特征圆弧字典(收集) TO EDIT 
                                                    Dictionary<string, List<MixedCAD_Arc>> AllBushArcDic = new Dictionary<string, List<MixedCAD_Arc>>();
                                                    for (int k = 0; k < AboutBushBList.Count; k++)
                                                    {
                                                        double BushBoardMaxY = AboutBushBList[k].OverheadLine.StartPoint.CustomerPoint.Y;
                                                        double BushBoardMinY = AboutBushBList[k].BottomLine.StartPoint.CustomerPoint.Y;
                                                        //导套圆弧集合
                                                        List<MixedCAD_Arc> TempBushCArcList = new List<MixedCAD_Arc>(AArcList);
                                                        TempBushCArcList = TempBushCArcList.FindAll(item =>
                                                        BushBoardMinY < item.CenterPoint.CustomerPoint.Y && item.CenterPoint.CustomerPoint.Y < BushBoardMaxY);
                                                        if (TempBushCArcList.Count > 0)
                                                            TempBushCArcList = TempBushCArcList.FindAll(item =>
                                                            CU.JudgeArcConformDimbush(item, BushTY, BushBY, DimLX, DimRX, BushLX, BushRX));
                                                        TempBushCArcList = TempBushCArcList.FindAll(item => item.Radius > 2.5);
                                                        //设置圆弧朝向 用于判断导套特征圆弧 数量
                                                        CU.SetArcDirListBySEPoint(TempBushCArcList);
                                                        if (TempBushCArcList.Count > 0)
                                                        {
                                                            string UID = AboutBushBList[k].BoardUID;
                                                            if (AllBushArcDic.ContainsKey(UID))
                                                                AllBushArcDic[UID].AddRange(TempBushCArcList);
                                                            else
                                                                AllBushArcDic.Add(UID, new List<MixedCAD_Arc>(TempBushCArcList));
                                                        }
                                                    }
                                                    //导套区域 客图有画 圆弧 的板UID
                                                    List<string> HasArcBoardUIDKeys = AllBushArcDic.Keys.ToList();
                                                    //导套区域 客图没画 圆弧 的板UID 
                                                    List<string> NoHasArcBoardUIDKeys = new List<string>();
                                                    if (AboutBushUIDList.Count > 0 && HasArcBoardUIDKeys.Count > 0)
                                                    {
                                                        List<string> allBushBoardUIDList = AboutBushUIDList.Select(item => item.BoardUID).ToList();
                                                        NoHasArcBoardUIDKeys = allBushBoardUIDList.Where(item => !HasArcBoardUIDKeys.Contains(item)).ToList();
                                                    }
                                                    //有 与套 相关的圆弧
                                                    if (HasArcBoardUIDKeys.Count > 0)
                                                    {
                                                        //连套索引信息(一组(4)横跨两块板)
                                                        List<ContinueBushIInfo> ContinueIndexesList = new List<ContinueBushIInfo>();
                                                        if (HasArcBoardUIDKeys.Count > 1)
                                                        {
                                                            for (int k = 0; k < HasArcBoardUIDKeys.Count - 1; k++)
                                                            {
                                                                int l = k + 1;
                                                                string KUID = HasArcBoardUIDKeys[k];
                                                                string IUID = HasArcBoardUIDKeys[l];
                                                                List<MixedCAD_Arc> KIUIDArcList = new List<MixedCAD_Arc>();
                                                                List<MixedCAD_Arc> KUIDArcList = AllBushArcDic[KUID];
                                                                List<MixedCAD_Arc> IUIDArcList = AllBushArcDic[IUID];
                                                                KIUIDArcList.AddRange(KUIDArcList);
                                                                KIUIDArcList.AddRange(IUIDArcList);
                                                                //判断导套圆弧是否跨板(一组板上没有四个方向的特征圆弧 默认跨板)
                                                                Boolean StraddlePlateF = CU.OneBoardNoBArcFourDic(KIUIDArcList);
                                                                //跨板 记录连套索引信息
                                                                if (StraddlePlateF)
                                                                {
                                                                    ContinueBushIInfo TCBushIndexInfo = new ContinueBushIInfo();
                                                                    TCBushIndexInfo.BeginBoardUID = KUID;
                                                                    TCBushIndexInfo.EndBoardUID = IUID;
                                                                    ContinueIndexesList.Add(TCBushIndexInfo);
                                                                }
                                                            }
                                                        }
                                                        //处理连套
                                                        if (ContinueIndexesList.Count > 0)
                                                        {
                                                            for (int k = 0; k < ContinueIndexesList.Count; k++)
                                                            {
                                                                List<string> BEUIDList = new List<string>();
                                                                string BUID = ContinueIndexesList[k].BeginBoardUID;
                                                                string EUID = ContinueIndexesList[k].EndBoardUID;
                                                                BEUIDList.Add(BUID);
                                                                BEUIDList.Add(EUID);
                                                                List<MixedCAD_Arc> BUIDArcList = AllBushArcDic[BUID];
                                                                List<MixedCAD_Arc> EUIDArcList = AllBushArcDic[EUID];
                                                                List<MixedCAD_Arc> BEUIDArcList = new List<MixedCAD_Arc>();
                                                                BEUIDArcList.AddRange(BUIDArcList);
                                                                BEUIDArcList.AddRange(EUIDArcList);
                                                                double ABBushMaxY = BEUIDArcList.Max(item => item.StartPoint.CustomerPoint.Y);
                                                                double ABBushMinY = BEUIDArcList.Min(item => item.EndPoint.CustomerPoint.Y);
                                                                int BushTDIndex = MergeBushTDInfoList.FindIndex(item => BEUIDList.Contains(item.BushTDBoard.BoardUID));
                                                                SingleItem BushItem = new SingleItem();
                                                                BushItem.AssembleCenterPointX = (double)AVRefSplitX;
                                                                if (BushTDIndex == -1)
                                                                {
                                                                    if (NozzleMesonExit)
                                                                    {
                                                                        BushItem.ItemCode = "SupportPinABush";
                                                                        BushItem.ItemNameType = DItemNameType.SupportPinABush;
                                                                    }
                                                                    else
                                                                    {
                                                                        BushItem.ItemCode = "NoNozzleMesonSupportPinABush";
                                                                        BushItem.ItemNameType = DItemNameType.NoNozzleMesonSupportPinABush;
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    BushItem.BushTDBoard = MergeBushTDInfoList[BushTDIndex].BushTDBoard;
                                                                    BushItem.BushTDPosType = MergeBushTDInfoList[BushTDIndex].BushTDPosType;
                                                                    if (NozzleMesonExit)
                                                                    {
                                                                        BushItem.ItemCode = "SupportPinBBush";
                                                                        BushItem.ItemNameType = DItemNameType.SupportPinBBush;
                                                                    }
                                                                    else
                                                                    {
                                                                        BushItem.ItemCode = "NoNozzleMesonSupportPinBBush";
                                                                        BushItem.ItemNameType = DItemNameType.NoNozzleMesonSupportPinBBush;
                                                                    }
                                                                }
                                                                BushItem.RealH = Convert.ToInt32(Math.Round(ABBushMaxY - ABBushMinY, 0));
                                                                BushItem.TheoryH = CU.BushCustomerLTranToTheoryL(BushItem.RealH);
                                                                Boolean BBushF = BushItem.ItemCode.Contains("BBush");
                                                                if (BBushF)
                                                                {
                                                                    SetSPGPBBushTH(MergeBushTDInfoList, BushItem);
                                                                    if (BushItem.BushBoardList.Count > 0)
                                                                    {
                                                                        List<string> bbushBCodeList = BushItem.BushBoardList.Select(item => item.BoardUID).ToList();
                                                                        string targetUID = BushItem.BushTDBoard.BoardUID;
                                                                        if (targetUID != null)
                                                                        {
                                                                            Boolean BF = bbushBCodeList.Contains(targetUID);
                                                                            if (BF)
                                                                            {
                                                                                int targetUIDIndex = BushItem.BushBoardList.FindIndex(item => item.BoardUID.Equals(targetUID));
                                                                                if (targetUIDIndex != -1)
                                                                                    BushItem.BushBoardList.RemoveAt(targetUIDIndex);
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                                BushItem.Dim = SItem.Dim;
                                                                BushItem.BushTD = SItem.BushTD;
                                                                BushItem.BushSize = SItem.BushSize;
                                                                BushItem.RelScrewHoleList = SItem.RelScrewHoleList;
                                                                BushItem.ItemNum = BushItem.RelScrewHoleList.Count;
                                                                CU.BushTransToProcessData("SPBush", BushItem);
                                                                ShareItemData.ItemList.Add(BushItem);
                                                            }
                                                        }
                                                        //有画圆弧 但无连套
                                                        List<BoardSectionItem> HasArcButNoConnBList = new List<BoardSectionItem>();
                                                        //先排除连套板干扰 剩下的每块板都去推算导套
                                                        if (ContinueIndexesList.Count > 0)
                                                        {
                                                            List<string> AllCBEUIDList = new List<string>();
                                                            List<string> AllCBUIDList = ContinueIndexesList.Select(item => item.BeginBoardUID).ToList();
                                                            List<string> AllCEUIDList = ContinueIndexesList.Select(item => item.EndBoardUID).ToList();
                                                            AllCBEUIDList.AddRange(AllCBUIDList);
                                                            AllCBEUIDList.AddRange(AllCEUIDList);
                                                            List<string> NOAllCEUIDList = AboutBushUIDList.Select(item => item.BoardUID).ToList().FindAll(item => !AllCBEUIDList.Contains(item));
                                                            HasArcButNoConnBList = AboutBushBList.FindAll(item => HasArcBoardUIDKeys.Contains(item.BoardUID));
                                                            HasArcButNoConnBList = HasArcButNoConnBList.FindAll(item => NOAllCEUIDList.Contains(item.BoardUID));
                                                            }
                                                        else
                                                            HasArcButNoConnBList = AboutBushBList.FindAll(item => HasArcBoardUIDKeys.Contains(item.BoardUID));

                                                        //处理有圆弧 非连套 
                                                        if (HasArcButNoConnBList.Count > 0)
                                                        {
                                                            for (int k = 0; k < HasArcButNoConnBList.Count; k++)
                                                            {
                                                                string BUID = HasArcButNoConnBList[k].BoardUID;
                                                                List<MixedCAD_Arc> OBBushArcList = AllBushArcDic[BUID];
                                                                SingleItem BushItem = new SingleItem();
                                                                BushItem.AssembleCenterPointX = (double)AVRefSplitX;
                                                                int BushTDIndex = MergeBushTDInfoList.FindIndex(item => HasArcButNoConnBList[k].BoardUID.Equals(item.BushTDBoard.BoardUID));
                                                                if (BushTDIndex == -1)
                                                                {
                                                                    if (NozzleMesonExit)
                                                                    {
                                                                        BushItem.ItemCode = "SupportPinABush";
                                                                        BushItem.ItemNameType = DItemNameType.SupportPinABush;
                                                                    }
                                                                    else
                                                                    {
                                                                        BushItem.ItemCode = "NoNozzleMesonSupportPinABush";
                                                                        BushItem.ItemNameType = DItemNameType.NoNozzleMesonSupportPinABush;
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    BushItem.BushTDBoard = MergeBushTDInfoList[BushTDIndex].BushTDBoard;
                                                                    BushItem.BushTDPosType = MergeBushTDInfoList[BushTDIndex].BushTDPosType;
                                                                    if (NozzleMesonExit)
                                                                        {
                                                                            BushItem.ItemCode = "SupportPinBBush";
                                                                            BushItem.ItemNameType = DItemNameType.SupportPinBBush;
                                                                        }
                                                                        else
                                                                        {
                                                                            BushItem.ItemCode = "NoNozzleMesonSupportPinBBush";
                                                                            BushItem.ItemNameType = DItemNameType.NoNozzleMesonSupportPinBBush;
                                                                        }
                                                                    }
                                                                    MixedCAD_Arc TLArc = OBBushArcList.Find(item => item.Dir == AngleDir.TL);
                                                                    MixedCAD_Arc TRArc = OBBushArcList.Find(item => item.Dir == AngleDir.TR);
                                                                    MixedCAD_Arc BLArc = OBBushArcList.Find(item => item.Dir == AngleDir.BL);
                                                                    MixedCAD_Arc BRArc = OBBushArcList.Find(item => item.Dir == AngleDir.BR);
                                                                    double? BushArcMaxY = null;
                                                                    double? BushArcMinY = null;
                                                                    Boolean TopPortF = TLArc != null && TRArc != null;
                                                                    Boolean BootomPortF = BLArc != null && BRArc != null;
                                                                    if (TopPortF)
                                                                        BushArcMaxY = TLArc.StartPoint.CustomerPoint.Y > TRArc.StartPoint.CustomerPoint.Y ? TLArc.StartPoint.CustomerPoint.Y : TRArc.StartPoint.CustomerPoint.Y;
                                                                    if (BootomPortF)
                                                                        BushArcMinY = BLArc.EndPoint.CustomerPoint.Y < BRArc.EndPoint.CustomerPoint.Y ? BLArc.EndPoint.CustomerPoint.Y : BRArc.EndPoint.CustomerPoint.Y;
                                                                    if (TopPortF && BootomPortF)
                                                                    {
                                                                        BushItem.RealH = Convert.ToInt32(Math.Round((double)BushArcMaxY - (double)BushArcMinY, 0));
                                                                        BushItem.HSplitInfo.SplitInfoList = SItem.HSplitInfo.SplitInfoList;
                                                                        BushItem.BushBoardList.Add(HasArcButNoConnBList[k]);
                                                                    }
                                                                    else
                                                                    {
                                                                        BushItem.HSplitInfo.SplitInfoList = SItem.HSplitInfo.SplitInfoList;
                                                                        if (TopPortF || BootomPortF)
                                                                        {
                                                                            if (TopPortF)
                                                                            {
                                                                                double BY = HasArcButNoConnBList[k].BottomLine.StartPoint.CustomerPoint.Y;
                                                                                BushItem.RealH = (int)(BushArcMaxY - BY);
                                                                            }
                                                                            if (BootomPortF)
                                                                            {
                                                                                double TY = HasArcButNoConnBList[k].OverheadLine.StartPoint.CustomerPoint.Y;
                                                                                BushItem.RealH = (int)(TY - BushArcMinY);
                                                                            }
                                                                            BushItem.BushBoardList.Add(HasArcButNoConnBList[k]);
                                                                        }
                                                                        //两端都没圆弧 就认为这个需要加到没画套的板UID中
                                                                        else
                                                                        NoHasArcBoardUIDKeys.Add(HasArcButNoConnBList[k].BoardUID);
                                                                    }
                                                                    BushItem.TheoryH = CU.BushCustomerLTranToTheoryL(BushItem.RealH);
                                                                    BushItem.Dim = SItem.Dim;
                                                                    Boolean BBushF = BushItem.ItemCode.Contains("BBush");
                                                                    if(BBushF)
                                                                    {
                                                                        SetSPGPBBushTH(MergeBushTDInfoList, BushItem);
                                                                        if(BushItem.BushBoardList.Count > 0)
                                                                        {
                                                                            List<string> bbushBCodeList =  BushItem.BushBoardList.Select(item => item.BoardUID).ToList();
                                                                            string targetUID = BushItem.BushTDBoard.BoardUID;
                                                                            if (targetUID != null)
                                                                            {
                                                                                Boolean BF = bbushBCodeList.Contains(targetUID);
                                                                                if (BF)
                                                                                {
                                                                                    int targetUIDIndex = BushItem.BushBoardList.FindIndex(item => item.BoardUID.Equals(targetUID));
                                                                                    if(targetUIDIndex != -1)
                                                                                        BushItem.BushBoardList.RemoveAt(targetUIDIndex);
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                    BushItem.BushTD = SItem.BushTD;
                                                                    BushItem.BushSize = SItem.BushSize;
                                                                    BushItem.RelScrewHoleList = SItem.RelScrewHoleList;
                                                                    BushItem.ItemNum = BushItem.RelScrewHoleList.Count;
                                                                    CU.BushTransToProcessData("SPBush", BushItem);
                                                                    ShareItemData.ItemList.Add(BushItem);
                                                            }
                                                        }
                                                    }

                                                //处理 检查没圆弧的套直径板 没画套相关的圆弧 导套穿过多少板 就算多少套
                                                if (NoHasArcBoardUIDKeys.Count > 0)
                                                {
                                                    List<BoardSectionItem> NDList = AboutBushBList.FindAll(item => NoHasArcBoardUIDKeys.Contains(item.BoardUID));
                                                    for (int bsi = 0; bsi < NDList.Count; bsi++)
                                                    {
                                                        SingleItem BushItem = new SingleItem();
                                                        BushItem.AssembleCenterPointX = (double)AVRefSplitX;
                                                        Boolean F = BushTDBoardUIDList.Contains(NDList[bsi].BoardUID);
                                                        if (F)
                                                        {
                                                            if (NozzleMesonExit)
                                                            {
                                                                BushItem.ItemCode = "SupportPinBBush";
                                                                BushItem.ItemNameType = DItemNameType.SupportPinBBush;
                                                            }
                                                            else
                                                            {
                                                                BushItem.ItemCode = "NoNozzleMesonSupportPinBBush";
                                                                BushItem.ItemNameType = DItemNameType.NoNozzleMesonSupportPinBBush;
                                                            }
                                                        }
                                                        else
                                                        {
                                                            if (NozzleMesonExit)
                                                            {
                                                                BushItem.ItemCode = "SupportPinABush";
                                                                BushItem.ItemNameType = DItemNameType.SupportPinABush;
                                                            }
                                                            else
                                                            {
                                                                BushItem.ItemCode = "NoNozzleMesonSupportPinABush";
                                                                BushItem.ItemNameType = DItemNameType.NoNozzleMesonSupportPinABush;
                                                            }
                                                        }
                                                        BushItem.BushBoardList.Add(NDList[bsi]);
                                                        BushItem.RealH = (int)BushSizeBoardList[bsi].PlateThick;
                                                        BushItem.TheoryH = CU.BushCustomerLTranToTheoryL(BushItem.RealH);
                                                        BushItem.Dim = SItem.Dim;
                                                        Boolean BBushF = BushItem.ItemCode.Contains("BBush");
                                                        if (BBushF)
                                                        {
                                                            SetSPGPBBushTH(MergeBushTDInfoList, BushItem);
                                                            if (BushItem.BushBoardList.Count > 0)
                                                            {
                                                                List<string> bbushBCodeList = BushItem.BushBoardList.Select(item => item.BoardUID).ToList();
                                                                string targetUID = BushItem.BushTDBoard.BoardUID;
                                                                if (targetUID != null)
                                                                {
                                                                    Boolean BF = bbushBCodeList.Contains(targetUID);
                                                                    if (BF)
                                                                    {
                                                                        int targetUIDIndex = BushItem.BushBoardList.FindIndex(item => item.BoardUID.Equals(targetUID));
                                                                        if (targetUIDIndex != -1)
                                                                            BushItem.BushBoardList.RemoveAt(targetUIDIndex);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        BushItem.BushTD = SItem.BushTD;
                                                        BushItem.BushSize = SItem.BushSize;
                                                        BushItem.RelScrewHoleList = SItem.RelScrewHoleList;
                                                        BushItem.ItemNum = BushItem.RelScrewHoleList.Count;
                                                        CU.BushTransToProcessData("SPBush", BushItem);
                                                        ShareItemData.ItemList.Add(BushItem);
                                                    }
                                                }
                                            }

                                        }


                                        //可能 有 避空区域 = SP Board - SP TD Board - 套
                                        List<BoardSectionItem> maybeBKBoardList = (List<BoardSectionItem>)ConvertUtils.DeepCopy(SPScopeBoardList);
                                        List<string> ExcludeBUIDList = new List<string>();
                                        if (MergeBushTDInfoList.Count > 0)
                                        {
                                            List<string> ExBushTDUIDList = MergeBushTDInfoList.Select(item => item.BushTDBoard.BoardUID).Distinct().ToList();
                                            ExcludeBUIDList.AddRange(ExBushTDUIDList);
                                        }
                                        if (BushSizeBoardList.Count > 0)
                                        {
                                            List<string> ExBushUIDList = BushSizeBoardList.Select(item => item.BoardUID).Distinct().ToList();
                                            ExcludeBUIDList.AddRange(ExBushUIDList);
                                        }
                                        if (SItem.TDBoard.BoardUID != null)
                                            ExcludeBUIDList.Add(SItem.TDBoard.BoardUID);
                                        if(ExcludeBUIDList.Count > 0)
                                        {
                                            ExcludeBUIDList = ExcludeBUIDList.Distinct().ToList();
                                            for (int bui = 0; bui < ExcludeBUIDList.Count; bui++)
                                            {
                                                int exIndex = maybeBKBoardList.FindIndex(item => item.BoardUID.Equals(ExcludeBUIDList[bui]));
                                                if (exIndex != -1)
                                                    maybeBKBoardList.RemoveAt(exIndex);
                                            }
                                        }

                                        if(maybeBKBoardList.Count > 0)
                                        {
                                            List<CSinglePartItem> AllRelatedBKVList = new List<CSinglePartItem>();
                                            List<double> maybeBKKeys = new List<double>();
                                            List<double> avKeyList = AVLineYDic.Keys.ToList();
                                            for (int bki = 0; bki < maybeBKBoardList.Count; bki++)
                                            {
                                                double maxY = Math.Round(maybeBKBoardList[bki].OverheadLine.StartPoint.TransSplitPoint.Y, 1) + 0.5;
                                                double minY = Math.Round(maybeBKBoardList[bki].BottomLine.StartPoint.TransSplitPoint.Y, 1) - 0.5;
                                                List<double> tempScopeKeys = avKeyList.FindAll(item => minY <= item && item <= maxY);
                                                if (tempScopeKeys.Count > 0)
                                                    maybeBKKeys.AddRange(tempScopeKeys);
                                            }
                                            List<MixedCAD_Line> BKVLines = new List<MixedCAD_Line>();
                                            if (maybeBKKeys.Count > 0)
                                                maybeBKKeys.ForEach(key => BKVLines.AddRange(AVLineYDic[key]));
                                            if (BKVLines.Count > 0)
                                            {
                                                //Merge BK Vline
                                                if (BKVLines.Count > 1)
                                                    BKVLines = ComputedUtils.MergeSimilarXVLineList(BKVLines);

                                                if (BKVLines.Count > 0 && AVRefSplitX != null)
                                                {
                                                    double BKrefX = (double)AVRefSplitX;
                                                    ScrewHole refScrewHole = SPList[0];

                                                    double refBSV = ParamsConfigData.StandardSPList.Find(item => item.Dimension == SItem.Dim).BushSize;
                                                    for (int j = 0; j < BKVLines.Count - 1; j++)
                                                    {
                                                        for (int k = 1; k < BKVLines.Count; k++)
                                                        {
                                                            if (k > j)
                                                            {
                                                                Boolean diffLengthF = Math.Abs(BKVLines[j].Length - BKVLines[k].Length) < 3;
                                                                double TempDim = Math.Abs(BKVLines[j].StartPoint.TransSplitPoint.X - BKVLines[k].StartPoint.TransSplitPoint.X);
                                                                //近似中心对称 计算误差在+- 0.2
                                                                double TwoLineSplitAgvCX = Math.Round((BKVLines[j].StartPoint.TransSplitPoint.X + BKVLines[k].StartPoint.TransSplitPoint.X) / 2, 1);
                                                                double LX = TwoLineSplitAgvCX - 5;
                                                                double RX = TwoLineSplitAgvCX + 5;
                                                                Boolean satF = LX <= BKrefX && BKrefX <= RX;
                                                                if (satF)
                                                                {
                                                                    Boolean F1 = refScrewHole.BK - 5 <= TempDim && TempDim <= refScrewHole.BK + 5;
                                                                    Boolean F2 = SItem.Dim < TempDim && TempDim <= refBSV;
                                                                    if (F1 && F2 && diffLengthF)
                                                                    {
                                                                        CSinglePartItem SPBKItem = new CSinglePartItem();
                                                                        SPBKItem.ItemType = ItemPartCodeType.BK;
                                                                        SPBKItem.LLine = BKVLines[j];
                                                                        SPBKItem.RLine = BKVLines[k];
                                                                        SPBKItem.XLength = TempDim;
                                                                        SPBKItem.YLength = Math.Round(Math.Abs(BKVLines[j].StartPoint.CustomerPoint.Y - BKVLines[k].EndPoint.CustomerPoint.Y), 0);
                                                                        SPBKItem.TVCPX = BKrefX;
                                                                        AllRelatedBKVList.Add(SPBKItem);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }

                                            List<ItemBKInfo> ResBKInfoList = new List<ItemBKInfo>();
                                            //SP 直径通孔板 = (SP Board - SP TD Board - 套)疑似避空区域 -避空
                                            List<BoardSectionItem> maybeDimThroughBList = (List<BoardSectionItem>)ConvertUtils.DeepCopyObject(maybeBKBoardList);
                                            maybeDimThroughBList = maybeDimThroughBList.FindAll(item => !item.BoardCode.Equals("fpBoard")
                                               && !item.BoardCode.Equals("epBoard"));
                                            if (AllRelatedBKVList.Count > 0)
                                            {
                                                List<double> BKValueList = AllRelatedBKVList.Select(item => item.XLength).Distinct().ToList();
                                                SItem.BK = (int)BKValueList.Max();
                                                for (int bki = 0; bki < AllRelatedBKVList.Count; bki++)
                                                {
                                                    List<DeadReckBKTempInfo> tempBKDetailList = new List<DeadReckBKTempInfo>();
                                                    double LSY = AllRelatedBKVList[bki].LLine.StartPoint.CustomerPoint.Y;
                                                    double LEY = AllRelatedBKVList[bki].LLine.EndPoint.CustomerPoint.Y;
                                                    double RSY = AllRelatedBKVList[bki].RLine.StartPoint.CustomerPoint.Y;
                                                    double REY = AllRelatedBKVList[bki].RLine.EndPoint.CustomerPoint.Y;
                                                    double tempbkH = Math.Round(AllRelatedBKVList[bki].YLength, 1);
                                                    double TY = LSY < RSY ? LSY : RSY;
                                                    double BY = LEY > REY ? LEY : REY;
                                                    int FirstBoardIndex = maybeBKBoardList.FindLastIndex(item => TY <= item.OverheadLine.StartPoint.CustomerPoint.Y);
                                                    int SecondBoardIndex = maybeBKBoardList.FindIndex(item => item.BottomLine.StartPoint.CustomerPoint.Y <= BY);
                                                    if (FirstBoardIndex != -1 && SecondBoardIndex != -1 && SecondBoardIndex >= FirstBoardIndex)
                                                    {
                                                        List<BoardSectionItem> TempAreaBList = maybeBKBoardList.GetRange(FirstBoardIndex, SecondBoardIndex - FirstBoardIndex + 1);
                                                        if (TempAreaBList.Count > 0)
                                                            TempAreaBList = TempAreaBList.FindAll(item => !item.BoardCode.Equals("fpBoard")
                                                                 && !item.BoardCode.Equals("epBoard"));
                                                        if (TempAreaBList.Count > 0)
                                                        {
                                                            TempAreaBList = TempAreaBList.OrderBy(item => item.plateLineNo).ToList();
                                                            ItemBKInfo tempbkInfo = new ItemBKInfo();
                                                            tempbkInfo.BKHH = tempbkH;
                                                            if (TempAreaBList.Count == 1)
                                                            {
                                                                BoardSectionItem targetBKBItem = TempAreaBList.First();
                                                                double bkbthick = Math.Round(targetBKBItem.PlateThick, 1);
                                                                if (tempbkH == bkbthick)
                                                                {
                                                                    DeadReckBKTempInfo tempbkdetail = new DeadReckBKTempInfo();
                                                                    tempbkdetail.BKInBoardUID = targetBKBItem.BoardUID;
                                                                    tempbkdetail.H = tempbkH;
                                                                    tempbkdetail.BKInBoardType = InBoardType.Through;
                                                                    tempBKDetailList.Add(tempbkdetail);
                                                                }
                                                                else
                                                                {
                                                                    if (tempbkH < bkbthick)
                                                                    {
                                                                        double bty = Math.Round(targetBKBItem.OverheadLine.StartPoint.CustomerPoint.Y, 1);
                                                                        double bby = Math.Round(targetBKBItem.BottomLine.StartPoint.CustomerPoint.Y, 1);
                                                                        Boolean F1 = Math.Round(TY, 1) == bty;
                                                                        Boolean F2 = Math.Round(BY, 1) == bby;
                                                                        DeadReckBKTempInfo tempbkdetail = new DeadReckBKTempInfo();
                                                                        if (F1)
                                                                            tempbkdetail.BKInBoardType = InBoardType.Up;
                                                                        if (F2)
                                                                            tempbkdetail.BKInBoardType = InBoardType.Down;
                                                                        tempbkdetail.BKInBoardUID = targetBKBItem.BoardUID;
                                                                        tempbkdetail.H = tempbkH;
                                                                        tempBKDetailList.Add(tempbkdetail);
                                                                    }
                                                                }
                                                            }
                                                            //避空连板
                                                            else
                                                            {

                                                                double bkBoardH = 0;
                                                                TempAreaBList.ForEach(item => bkBoardH += item.PlateThick);
                                                                bkBoardH = Math.Round(bkBoardH, 1);
                                                                if (tempbkH == bkBoardH)
                                                                {
                                                                    for (bki = 0; bki < TempAreaBList.Count; bki++)
                                                                    {
                                                                        DeadReckBKTempInfo tempbkdetail = new DeadReckBKTempInfo();
                                                                        tempbkdetail.BKInBoardType = InBoardType.Through;
                                                                        tempbkdetail.BKInBoardUID = TempAreaBList[bki].BoardUID;
                                                                        tempbkdetail.H = TempAreaBList[bki].PlateThick;
                                                                        tempBKDetailList.Add(tempbkdetail);
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    if (tempbkH < bkBoardH)
                                                                    if (tempbkH < bkBoardH)
                                                                    {
                                                                        double diffH = bkBoardH - tempbkH;
                                                                        BoardSectionItem firstBKBItem = TempAreaBList.First();
                                                                        BoardSectionItem lastBKBItem = TempAreaBList.Last();
                                                                        double bty = Math.Round(firstBKBItem.OverheadLine.StartPoint.CustomerPoint.Y, 1);
                                                                        double bby = Math.Round(lastBKBItem.BottomLine.StartPoint.CustomerPoint.Y, 1);
                                                                        Boolean F1 = Math.Round(TY, 1) == bty;
                                                                        Boolean F2 = Math.Round(BY, 1) == bby;
                                                                        if (F1)
                                                                        {
                                                                            DeadReckBKTempInfo lastbkInfo = new DeadReckBKTempInfo();
                                                                            double lastbkH = lastBKBItem.PlateThick - diffH;
                                                                            lastbkInfo.BKInBoardType = InBoardType.Up;
                                                                            lastbkInfo.BKInBoardUID = lastBKBItem.BoardUID;
                                                                            lastbkInfo.H = lastbkH;
                                                                            tempBKDetailList.Add(lastbkInfo);
                                                                            List<BoardSectionItem> operBList = (List<BoardSectionItem>)ConvertUtils.DeepCopyObject(TempAreaBList);
                                                                            operBList.RemoveAt(operBList.Count - 1);
                                                                            if (operBList.Count > 0)
                                                                            {
                                                                                for (int op = 0; op < operBList.Count; op++)
                                                                                {
                                                                                    DeadReckBKTempInfo tempbkdetail = new DeadReckBKTempInfo();
                                                                                    tempbkdetail.BKInBoardType = InBoardType.Through;
                                                                                    tempbkdetail.BKInBoardUID = operBList[op].BoardUID;
                                                                                    tempbkdetail.H = operBList[op].PlateThick;
                                                                                    tempBKDetailList.Add(tempbkdetail);
                                                                                }
                                                                            }
                                                                        }
                                                                        if (F2)
                                                                        {
                                                                            DeadReckBKTempInfo firstbkInfo = new DeadReckBKTempInfo();
                                                                            double firstbkH = firstBKBItem.PlateThick - diffH;
                                                                            firstbkInfo.BKInBoardType = InBoardType.Down;
                                                                            firstbkInfo.BKInBoardUID = firstBKBItem.BoardUID;
                                                                            firstbkInfo.H = firstbkH;
                                                                            tempBKDetailList.Add(firstbkInfo);
                                                                            List<BoardSectionItem> operBList = (List<BoardSectionItem>)ConvertUtils.DeepCopyObject(TempAreaBList);
                                                                            operBList.RemoveAt(0);
                                                                            if (operBList.Count > 0)
                                                                            {
                                                                                for (int op = 0; op < operBList.Count; op++)
                                                                                {
                                                                                    DeadReckBKTempInfo tempbkdetail = new DeadReckBKTempInfo();
                                                                                    tempbkdetail.BKInBoardType = InBoardType.Through;
                                                                                    tempbkdetail.BKInBoardUID = operBList[op].BoardUID;
                                                                                    tempbkdetail.H = operBList[op].PlateThick;
                                                                                    tempBKDetailList.Add(tempbkdetail);
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }

                                                            if (tempBKDetailList.Count > 0)
                                                            {
                                                                tempBKDetailList = tempBKDetailList.Distinct(new DeadReckBKTempInfoComparer()).ToList();
                                                                List<string> BoardUIDList = tempBKDetailList.Select(item => item.BKInBoardUID).ToList();
                                                                tempbkInfo.BoardUIDList.AddRange(BoardUIDList);
                                                                tempbkInfo.DetailInfoList.AddRange(tempBKDetailList);
                                                            }
                                                            ResBKInfoList.Add(tempbkInfo);
                                                        }
                                                    }
                                                }
                                                if (ResBKInfoList.Count > 0)
                                                {
                                                    ResBKInfoList = ResBKInfoList.Distinct(new ItemBKInfoComparer()).ToList();
                                                    SItem.ItemBKInfoList.AddRange(ResBKInfoList);
                                                    List<List<string>> BUIDList = ResBKInfoList.Select(item => item.BoardUIDList).ToList();
                                                    List<string> resBUIDList = new List<string>();
                                                    BUIDList.ForEach(item => resBUIDList.AddRange(item));
                                                    resBUIDList = resBUIDList.Distinct().ToList();
                                                    for (int ti = 0; ti < resBUIDList.Count; ti++)
                                                    {
                                                        Boolean hasF = resBUIDList[ti].Contains("fangtie");
                                                        if (hasF)
                                                            maybeDimThroughBList = maybeDimThroughBList.FindAll(item => !item.BoardUID.Contains("fangtie"));
                                                        int delIndex = maybeDimThroughBList.FindIndex(item => item.BoardUID.Equals(resBUIDList[ti]));
                                                        if (delIndex != -1)
                                                            maybeDimThroughBList.RemoveAt(delIndex);
                                                    }
                                                    if (maybeDimThroughBList.Count > 0)
                                                        SItem.ItemDimThroughHBList = maybeDimThroughBList;
                                                }
                                                else
                                                    SItem.ItemDimThroughHBList = maybeDimThroughBList;
                                            }


                                        }
                                        CU.SPGPTransToProcessData("SP", SItem);
                                        ShareItemData.ItemList.Add(SItem);
                                    }
                                }

                            }
                            
                        }

                    }

                }
            }
            catch (Exception ex)
            {

            }
        }

        //SP/GP BBush Set BushTH
        public static void SetSPGPBBushTH(List<PartBushTDArgItem> bushTDArg, SingleItem BushItem)
        {
            List<string> searchBUIDList = BushItem.BushBoardList.Select(item => item.BoardUID).ToList();
            if(searchBUIDList.Count > 0)
            {

                if (bushTDArg.Count > 0)
                {
                    for(int i = 0; i < bushTDArg.Count; i++)
                    {
                        string refTDBUID = bushTDArg[i].BushTDBoard.BoardUID;
                        Boolean F = searchBUIDList.Contains(refTDBUID);
                        if (F)
                            BushItem.BushTH = (decimal)bushTDArg[i].BushTH;
                    }
                }
            }
        }

        public static void SetFangtieInfo(Dictionary<double, List<MixedCAD_Line>> AVLineYDic, Dictionary<double, List<MixedCAD_Line>> OBLineYDic,
            List<MixedCAD_Line> CenterLineList)
        {
            FangtieShareData.FLXInfo = new FangtieXInfo();
            FangtieShareData.FRXInfo = new FangtieXInfo();

            FangtieShareData.NOFLXInfo = new FangtieXInfo();
            FangtieShareData.NOFRXInfo = new FangtieXInfo();

            //LR Stand Up Flag
            Boolean LFStandF = false;
            Boolean RFStandF = false;
            List<double> centerXList = CenterLineList.Select(item => item.StartPoint.CustomerPoint.X).Distinct().ToList();
            List<BoardSectionItem> AssemblyBoardList = AssemblyShareData.ASectionList;

            MixedCAD_Point modlHInfo = RecognizeUtils.WholeTopViewData.ModlCenterInfo;
            int LastFIndex = AssemblyBoardList.FindIndex(item => item.BoardCode.Equals("fangtie"));
            if (LastFIndex == -1)
            {
                //distinguish GP SP Scope
                double SFWidth = CU.FangtieSPWidth(MoldBaseShare.Width);
                double HalfW = SFWidth / 2;
                double CPX = modlHInfo.CustomerPoint.X;
                double RFX = CPX - HalfW + SFWidth;
                double LFX = CPX + HalfW - SFWidth;
                FangtieShareData.HasLRF = false;
                FangtieShareData.NOFLXInfo.CustomerX = LFX;
                FangtieShareData.NOFRXInfo.CustomerX = RFX;
                FangtieShareData.NOFLXInfo.F = true;
                FangtieShareData.NOFRXInfo.F = true;
                return;
            }
            else
                FangtieShareData.HasLRF = true;

            ReckFangtieInfo reckLFInfo = FangtieShareData.reckLFInfo;
            reckLFInfo.fPosType = FPosType.L;
            ReckFangtieInfo reckRFInfo = FangtieShareData.reckRFInfo;
            reckRFInfo.fPosType = FPosType.R;
            ReckFangtieInfo reckCFInfo = FangtieShareData.reckCFInfo;
            reckCFInfo.fPosType = FPosType.C;

            SpcialAssemType assmeType = SpcialAssemType.Normal;
            int hrLastIndex = AssemblyShareData.ASectionList.FindLastIndex(item => item.BoardCode.Equals("hrBoard"));
            int bpFirstIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("bpBoard"));
            Boolean spcialF = hrLastIndex + 1 == bpFirstIndex;
            if (spcialF)
                assmeType = SpcialAssemType.hrOverbp;

            List<double> BeTweenLVKeys = new List<double>();
            double FHigh = 0;
            double? VSY = null;
            double? VEY = null;

            if (assmeType == SpcialAssemType.Normal)
            {
                BoardSectionItem PerFBoader = AssemblyBoardList[LastFIndex - 1];
                BoardSectionItem bpBoarder = AssemblyBoardList.Find(item => item.BoardCode.Equals("bpBoard"));
                VSY = PerFBoader.BottomLine.StartPoint.CustomerPoint.Y;
                VEY = bpBoarder.OverheadLine.StartPoint.CustomerPoint.Y;
                FHigh = (double)VSY - (double)VEY;
                List<double> VKeys = AVLineYDic.Keys.ToList();
                BeTweenLVKeys = VKeys.FindAll(item => VEY <= item && item <= VSY);
            }

            if(assmeType == SpcialAssemType.hrOverbp)
            {
                BoardSectionItem PerFBoader = AssemblyBoardList[LastFIndex - 1];
                int hrIndex =  AssemblyBoardList.FindIndex(item => item.BoardCode.Equals("hrBoard"));
                BoardSectionItem bpBoarder = AssemblyBoardList[hrIndex];
                VSY = PerFBoader.BottomLine.StartPoint.CustomerPoint.Y;
                VEY = bpBoarder.OverheadLine.StartPoint.CustomerPoint.Y;
                FHigh = (double)VSY - (double)VEY;
                List<double> VKeys = AVLineYDic.Keys.ToList();
                BeTweenLVKeys = VKeys.FindAll(item => VEY <= item && item <= VSY);
            }

            List<double> maybeFangtieXList = new List<double>();
            List<MixedCAD_Line> BetweenFAreaVList = new List<MixedCAD_Line>();
            //convex 
            List<MixedCAD_Line> maybeFConvexVList = new List<MixedCAD_Line>();
            List<MixedCAD_Line> maybeLFConvexVList = new List<MixedCAD_Line>();
            List<MixedCAD_Line> maybeRFConvexVList = new List<MixedCAD_Line>();
            double? HStandBLX = null;
            double? HStandBRX = null;
            //Step1 calculate Two Side Boundary X 
            int fpIndex = AssemblyBoardList.FindIndex(item => item.BoardCode.Equals("fpBoard"));
            int epIndex = AssemblyBoardList.FindIndex(item => item.BoardCode.Equals("epBoard"));
            //epfp Two Side Boundary X
            if (fpIndex != -1 || epIndex != -1)
            {
                double? epfpBLX = null;
                double? epfpBRX = null;
                double? fpBoardLX = null;
                double? fpBoardRX = null;
                double? epBoardLX = null;
                double? epBoardRX = null;
                if (fpIndex != -1)
                {
                    fpBoardLX = AssemblyBoardList[fpIndex].boardLRBoundInfo.BoardLX;
                    fpBoardRX = AssemblyBoardList[fpIndex].boardLRBoundInfo.BoardRX;
                }
                if (epIndex != -1)
                {
                    epBoardLX = AssemblyBoardList[epIndex].boardLRBoundInfo.BoardLX;
                    epBoardRX = AssemblyBoardList[epIndex].boardLRBoundInfo.BoardRX;
                }
                if (fpBoardLX != null && epBoardLX != null)
                    epfpBLX = fpBoardLX > epBoardLX ? fpBoardLX : epBoardLX;
                else
                {
                    if (fpBoardLX != null && epBoardLX == null)
                        epfpBLX = fpBoardLX;
                    if (fpBoardLX == null && epBoardLX != null)
                        epfpBLX = epBoardLX;
                }
                if (fpBoardRX != null && epBoardRX != null)
                    epfpBRX = fpBoardRX < epBoardRX ? fpBoardRX : epBoardRX;
                else
                {
                    if (fpBoardRX != null && epBoardRX == null)
                        epfpBRX = fpBoardRX;
                    if (fpBoardRX == null && epBoardRX != null)
                        epfpBRX = epBoardRX;
                }

                if (epfpBLX != null && epfpBRX != null)
                {
                    FangtieShareData.FLXInfo.CustomerX = (double)epfpBLX;
                    FangtieShareData.FRXInfo.CustomerX = (double)epfpBRX;
                }
            }

            //Step2. calculate Stand Up X Coor Value
            List<BoardSectionItem> HStandBoardList = new List<BoardSectionItem>();
            List<string> HStandBCodeList = new List<string> { "aBoard", "bBoard", "stBoard" };
            HStandBoardList = AssemblyBoardList.FindAll(item => HStandBCodeList.Contains(item.BoardCode)).ToList();
            if (HStandBoardList.Count > 0)
            {
                List<double> HWidthList = HStandBoardList.Select(item => item.PlateWidth).ToList();
                if (HWidthList.Count > 0)
                {
                    HWidthList = HWidthList.Distinct().ToList();
                    // A/B/st Same Width
                    if (HWidthList.Count == 1)
                    {
                        HStandBLX = HStandBoardList[0].boardLRBoundInfo.BoardLX;
                        HStandBRX = HStandBoardList[0].boardLRBoundInfo.BoardRX;
                     }
                    //A/B/st Diff Width
                    else
                    {
                        double? refBoardWidth = null;
                        double wDiff = HWidthList.Max() - HWidthList.Min();
                        if (wDiff > 6)
                            refBoardWidth = HWidthList.Min();
                        else
                            refBoardWidth = HWidthList.GroupBy(n => n).OrderByDescending(g => g.Count()).First().Key;
                        if (refBoardWidth != null)
                        {
                            BoardSectionItem refBoardItem = HStandBoardList.Find(item => item.PlateWidth == refBoardWidth);
                            HStandBLX = refBoardItem.boardLRBoundInfo.BoardLX;
                            HStandBRX = refBoardItem.boardLRBoundInfo.BoardRX;
                        }
                    }
                }
            }

            //Step3. Judge LR Stand Up Flag
            List<MixedCAD_Line> allVList = new List<MixedCAD_Line>();
            List<double> allVKeys = AVLineYDic.Keys.ToList();
            if (allVKeys.Count > 0)
                allVKeys.ForEach(item => allVList.AddRange(AVLineYDic[item]));
            if(allVKeys.Count > 0)
            {
                if (HStandBLX != null)
                {
                    double tempBLX = (double)HStandBLX;
                    Boolean LSF = CU.JudgeFangtieAreaExitStandUpX(allVList, tempBLX, (double)VSY, (double)VEY);
                    if (LSF)
                    {
                        LFStandF = true;
                        reckLFInfo.fangtieAppType = FangtieAppType.Stand;
                    }
                }
                if (HStandBRX != null)
                {
                    double tempBRX = (double)HStandBRX;
                    Boolean RRF = CU.JudgeFangtieAreaExitStandUpX(allVList, tempBRX, (double)VSY, (double)VEY);
                    if (RRF)
                    {
                        RFStandF = true;
                        reckRFInfo.fangtieAppType = FangtieAppType.Stand;
                    }
                }
            }
          
            //Step4. Collection Same High Fngaite Line
            if (BeTweenLVKeys.Count > 0)
            {
                BeTweenLVKeys.ForEach(key =>
                {
                    BetweenFAreaVList.AddRange(AVLineYDic[key]);
                    maybeFConvexVList.AddRange(AVLineYDic[key]);
                });

                //Filter
                if (BetweenFAreaVList.Count > 0)
                    BetweenFAreaVList = BetweenFAreaVList.FindAll(item => 0 <= Math.Round(item.EndPoint.CustomerPoint.Y - (double)VEY, 0)
                    && 0 <= Math.Round((double)VSY - item.StartPoint.CustomerPoint.Y, 0));

                if (BetweenFAreaVList.Count > 0)
                {
                    //Sort Out By X Coor X -> KEY
                    Dictionary<double, List<MixedCAD_Line>> VSameXDic = new Dictionary<double, List<MixedCAD_Line>>();
                    for (int i = 0; i < BetweenFAreaVList.Count; i++)
                    {
                        if (VSameXDic.ContainsKey(BetweenFAreaVList[i].StartPoint.CustomerPoint.X))
                        {
                            List<MixedCAD_Line> target = VSameXDic[BetweenFAreaVList[i].StartPoint.CustomerPoint.X];
                            target.Add(BetweenFAreaVList[i]);
                        }
                        else
                            VSameXDic.Add(BetweenFAreaVList[i].StartPoint.CustomerPoint.X, new List<MixedCAD_Line>() { BetweenFAreaVList[i] });
                    }
                    BetweenFAreaVList.Clear();
                    BeTweenLVKeys.Clear();
                    if (VSameXDic.Keys.Count > 0)
                    {
                        BeTweenLVKeys = VSameXDic.Keys.ToList();
                        BeTweenLVKeys = BeTweenLVKeys.OrderBy(item => item).ToList();
                        for (int j = 0; j < BeTweenLVKeys.Count; j++)
                        {
                            List<MixedCAD_Line> tempList = VSameXDic[BeTweenLVKeys[j]];
                            if (tempList.Count > 0)
                            {
                                if (tempList.Count == 1)
                                    BetweenFAreaVList.Add(tempList[0]);
                                else if (tempList.Count > 1)
                                {
                                    tempList = tempList.OrderByDescending(item => item.StartPoint.CustomerPoint.Y).ToList();
                                    Boolean ConnF = CU.SameXCanConn(tempList);
                                    if (ConnF)
                                    {
                                        MixedCAD_Line SYL = tempList[0];
                                        MixedCAD_Line EYL = tempList[tempList.Count - 1];
                                        MixedCAD_Line TItem = new MixedCAD_Line();
                                        TItem.SPChamferFlag = SYL.SPChamferFlag;
                                        TItem.SCLine = SYL.SCLine;
                                        TItem.EPChamferFlag = EYL.EPChamferFlag;
                                        TItem.ECLine = EYL.ECLine;
                                        TItem.StartPoint.CustomerPoint.X = SYL.StartPoint.CustomerPoint.X;
                                        TItem.EndPoint.CustomerPoint.X = SYL.EndPoint.CustomerPoint.X;
                                        TItem.StartPoint.CustomerPoint.Y = SYL.StartPoint.CustomerPoint.Y;
                                        TItem.EndPoint.CustomerPoint.Y = EYL.EndPoint.CustomerPoint.Y;
                                        BetweenFAreaVList.Add(TItem);
                                    }
                                }
                            }
                        }
                    }
                }

                //查看这个范围内几乎和方铁区间高度等高的竖线X坐标
                if (BetweenFAreaVList.Count > 0)
                {
                    for (int i = 0; i < BetweenFAreaVList.Count; i++)
                    {
                        double VL = BetweenFAreaVList[i].StartPoint.CustomerPoint.Y - BetweenFAreaVList[i].EndPoint.CustomerPoint.Y;
                        if (BetweenFAreaVList[i].SPChamferFlag)
                        {
                            double SCSY = BetweenFAreaVList[i].SCLine.StartPoint.CustomerPoint.Y;
                            double SCEY = BetweenFAreaVList[i].SCLine.EndPoint.CustomerPoint.Y;
                            double bigSCY = SCSY > SCEY ? SCSY : SCEY;
                            if(BetweenFAreaVList[i].StartPoint.CustomerPoint.Y < bigSCY)
                            {
                                double smallSCY = SCSY < SCEY ? SCSY : SCEY;
                                VL += bigSCY - smallSCY;
                            }
                        }
                        if (BetweenFAreaVList[i].EPChamferFlag)
                        {
                            double ECSY = BetweenFAreaVList[i].ECLine.StartPoint.CustomerPoint.Y;
                            double ECEY = BetweenFAreaVList[i].ECLine.EndPoint.CustomerPoint.Y;
                            double smallECY = ECSY < ECEY ? ECSY : ECEY;
                            if (BetweenFAreaVList[i].EndPoint.CustomerPoint.Y > smallECY)
                            {
                                double bigECY = ECSY > ECEY ? ECSY : ECEY;
                                VL += bigECY - smallECY;
                            }
                        }
                        // >= 0.9
                        double conformToFL = Math.Round(FHigh, 0) * 0.9;
                        if (Math.Round(VL, 0) >= conformToFL)
                            maybeFangtieXList.Add(BetweenFAreaVList[i].StartPoint.CustomerPoint.X);
                    }
                }

                //Reckon Probability
                Boolean exitLXF = false;
                Boolean exitRXF = false;
                //Filter By X Scope
                if (maybeFangtieXList.Count > 0)
                {
                    if (LFStandF)
                    {
                        int HStandBLXIndex = maybeFangtieXList.FindIndex(item => item != (double)HStandBLX);
                        if(HStandBLXIndex != -1)
                        {
                            exitLXF = true;
                            maybeFangtieXList = maybeFangtieXList.FindAll(item => item != (double)HStandBLX);
                        }
                    }
                    if (RFStandF)
                    {
                        int HStandBRXIndex = maybeFangtieXList.FindIndex(item => item != (double)HStandBLX);
                        if(HStandBRXIndex != -1)
                        {
                            exitRXF = true;
                            maybeFangtieXList = maybeFangtieXList.FindAll(item => item != (double)HStandBRX);
                        }
                    }
                }
                maybeFangtieXList = maybeFangtieXList.OrderBy(item => item).ToList();

                Boolean ConF1 = maybeFangtieXList.Count >= 4 && (exitLXF || exitRXF);
                Boolean ConF2 = maybeFangtieXList.Count > 0 && CenterLineList.Count > 0;
                //Use CenterLine To Filter Disturb XCoor
                if (ConF1 && ConF2)
                {
                    List<double> dupCMaybeFXList = new List<double>(maybeFangtieXList);
                    //LR MayBe Symmetry Misjudge
                    if (maybeFangtieXList.Count > 1)
                    {
                        List<MixedCAD_Line> TargetCList = (List<MixedCAD_Line>)ConvertUtils.DeepCopyObject(CenterLineList);
                        if (AssemblyBoardList.Count > 0)
                        {
                            FullInfoLine FirstBRef = AssemblyBoardList[0].OverheadLine;
                            double MayBeCX = Math.Round((FirstBRef.StartPoint.CustomerPoint.X + FirstBRef.EndPoint.CustomerPoint.X) / 2, 0);
                            //Center Center Line MabyBe Repeat 
                            List<MixedCAD_Line> CLCollection = TargetCList.FindAll(item => Math.Round(item.StartPoint.CustomerPoint.X, 0) == MayBeCX);
                            if (CLCollection.Count > 0)
                            {
                                for (int i = 0; i < CLCollection.Count; i++)
                                {
                                    int RCIndex = TargetCList.FindIndex(item => item.StartPoint == CLCollection[i].StartPoint
                                    && item.EndPoint == CLCollection[i].EndPoint);
                                    if (RCIndex != -1)
                                        TargetCList.RemoveAt(RCIndex);
                                }
                            }
                        }
                        if (TargetCList.Count > 0)
                        {
                            for (int ci = 0; ci < TargetCList.Count; ci++)
                            {
                                for (int i = 0; i < maybeFangtieXList.Count - 1; i++)
                                {
                                    int j = i + 1;
                                    Boolean CF = Math.Round(TargetCList[ci].StartPoint.CustomerPoint.X, 1) == 
                                        Math.Round((maybeFangtieXList[i] + maybeFangtieXList[j]) / 2, 1);
                                    if (CF)
                                    {
                                        dupCMaybeFXList.Remove(maybeFangtieXList[i]);
                                        dupCMaybeFXList.Remove(maybeFangtieXList[j]);
                                    }
                                }
                            }
                        }
                    }
                    maybeFangtieXList = dupCMaybeFXList;
                }
            }

            ////Step4.1 有些画法 是避空和方铁公用一条线 然后还有一点点斜线 TO CONTINUE
            //// fit OBLList
            //List<double> OBVKeys = OBLineYDic.Keys.ToList();
            //List<double> BfangtieOBList = OBVKeys.FindAll(item => VEY <= item && item <= VSY);
            //List<MixedCAD_Line> targetOBList = new List<MixedCAD_Line>();
            //if (BfangtieOBList.Count > 0)
            //    BfangtieOBList.ForEach(item => targetOBList.AddRange(OBLineYDic[item]));
            //if (targetOBList.Count > 0)
            //{
            //    if(FangtieShareData.FLXInfo != null && FangtieShareData.FRXInfo != null)
            //    {
            //        double epfpLX = (double)FangtieShareData.FLXInfo.SplitX;
            //        double epfpRX = (double)FangtieShareData.FRXInfo.SplitX;
            //        targetOBList = targetOBList.FindAll(item => item.StartPoint.CustomerPoint.X < epfpLX || item.StartPoint.CustomerPoint.X > epfpRX).ToList();
            //        if(targetOBList.Count > 0)
            //        {

            //        }
            //    }
            //}

            //Step5  distinguish Diff Scene
            Boolean epfpF = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("epBoard") ||
            item.BoardCode.Equals("fpBoard")) != -1;
            if (epfpF)
            {
                //Step 5.1 epfpBoard Two Sides Same High Limit X + Stand Up X  = width
                //L
                if (LFStandF)
                {
                    int LnearIndex = maybeFangtieXList.FindLastIndex(item => item < FangtieShareData.FLXInfo.CustomerX);
                    if(LnearIndex != -1)
                    {
                        double nearLX = maybeFangtieXList[LnearIndex];
                        double tempBLX = (double)HStandBLX;
                        reckLFInfo.Width = Math.Abs(Math.Round(tempBLX - nearLX, 0));
                        reckLFInfo.LX = tempBLX;
                        reckLFInfo.RX = nearLX;
                    }
                } 
                else
                {
                    List<double> LList = maybeFangtieXList.FindAll(item => item < FangtieShareData.FLXInfo.CustomerX);
                    if(LList.Count > 1)
                    {
                        double tempBLX = (double)HStandBLX;
                        double minX =LList.Min();
                        double maxX = LList.Max();
                        reckLFInfo.Width = Math.Round(maxX - minX, 0);
                        reckLFInfo.LX = minX;
                        reckLFInfo.RX = maxX;
                        if(minX < tempBLX)
                            reckLFInfo.fangtieAppType = FangtieAppType.tu;
                        else
                            reckLFInfo.fangtieAppType = FangtieAppType.ao;
                    }
                }
                //R
                if (RFStandF)
                {
                    int RnearIndex = maybeFangtieXList.FindIndex(item => item > FangtieShareData.FRXInfo.CustomerX);
                    if (RnearIndex != -1)
                    {
                        double nearRX = maybeFangtieXList[RnearIndex];
                        double tempBRX = (double)HStandBRX;
                        reckRFInfo.Width = Math.Abs(Math.Round(nearRX - tempBRX, 0));
                        reckRFInfo.LX = nearRX;
                        reckRFInfo.RX = tempBRX;
                    }
                }
                else
                {
                    List<double> RList = maybeFangtieXList.FindAll(item => item > FangtieShareData.FRXInfo.CustomerX);
                    if (RList.Count > 1)
                    {
                        double tempBRX = (double)HStandBRX;
                        double minX = RList.Min();
                        double maxX = RList.Max();
                        reckRFInfo.Width = Math.Round(maxX - minX, 0);
                        reckRFInfo.LX = minX;
                        reckRFInfo.RX = maxX;
                        if (maxX > tempBRX)
                            reckRFInfo.fangtieAppType = FangtieAppType.tu;
                        else
                            reckRFInfo.fangtieAppType = FangtieAppType.ao;
                    }
                }
                //Check 3 Fnagtie Scene
                List<double> betwwenXList = maybeFangtieXList.FindAll(item => FangtieShareData.FLXInfo.SplitX < item 
                && item < FangtieShareData.FRXInfo.SplitX);
                int cfxNum = betwwenXList.Count;
                if (cfxNum > 1)
                {
                    if(cfxNum % 2 == 0)
                    {
                        int p1Index = cfxNum / 2 - 1;
                        int p2Index = cfxNum / 2;
                        reckCFInfo.LX = betwwenXList[p1Index];
                        reckCFInfo.RX = betwwenXList[p2Index];
                        reckCFInfo.Width = Math.Round((double)reckCFInfo.RX - (double)reckCFInfo.LX, 0);
                    }
                    else
                    {
                        int p1Index = cfxNum / 2;
                        int p2Index = cfxNum / 2 + 1;
                        reckCFInfo.LX = betwwenXList[p1Index];
                        reckCFInfo.RX = betwwenXList[p2Index];
                        reckCFInfo.Width = Math.Round((double)reckCFInfo.RX - (double)reckCFInfo.LX, 0);
                    }
                }
            }
            else
            {
                int maybeFXNum = maybeFangtieXList.Count;
                if(maybeFXNum >= 2)
                {
                    //Assert Stand Up 
                    if (maybeFXNum == 2)
                    {
                        reckLFInfo.fangtieAppType = FangtieAppType.Stand;
                        reckLFInfo.LX = (double)HStandBLX;
                        reckLFInfo.RX = maybeFangtieXList[0];
                        reckLFInfo.Width = Math.Round((double)reckLFInfo.RX - (double)reckLFInfo.LX, 0);
                        reckRFInfo.fangtieAppType = FangtieAppType.Stand;
                        reckRFInfo.LX = maybeFangtieXList[1];
                        reckRFInfo.RX = (double)HStandBRX;
                        reckRFInfo.Width = Math.Round((double)reckRFInfo.RX - (double)reckRFInfo.LX, 0);
                    }

                    else
                    {
                        double mostOutSideLX = maybeFangtieXList.Min(); 
                        double mostOutSideRX = maybeFangtieXList.Max();
                        double tempBLX = (double)HStandBLX;
                        double tempBRX = (double)HStandBRX;

                        if (!LFStandF)
                        {
                            if(mostOutSideLX < tempBLX)
                                reckLFInfo.fangtieAppType = FangtieAppType.tu;
                            else
                                reckLFInfo.fangtieAppType = FangtieAppType.ao;
                        }
                        if (!RFStandF)
                        {
                            if (mostOutSideRX > tempBRX)
                                reckRFInfo.fangtieAppType = FangtieAppType.tu;
                            else
                                reckRFInfo.fangtieAppType = FangtieAppType.ao;
                        }

                        //LRC Set Arg
                        //L
                        if (LFStandF)
                        {
                            reckLFInfo.LX = tempBLX;
                            reckLFInfo.RX = mostOutSideLX;
                            maybeFangtieXList.RemoveAt(0);
                        }
                        else
                        {
                            reckLFInfo.LX = maybeFangtieXList[0];
                            reckLFInfo.RX = maybeFangtieXList[1];
                            maybeFangtieXList.RemoveAt(0);
                            maybeFangtieXList.RemoveAt(0);
                        }
                        reckLFInfo.Width = Math.Round((double)reckLFInfo.RX - (double)reckLFInfo.LX, 0);
                        //R
                        if (RFStandF)
                        {
                            int lastIndex = maybeFangtieXList.Count - 1;
                            reckRFInfo.LX = maybeFangtieXList[lastIndex];
                            reckRFInfo.RX = tempBRX;
                            maybeFangtieXList.RemoveAt(lastIndex);
                        }
                        else
                        {
                            int lastIndex = maybeFangtieXList.Count - 1;
                            reckRFInfo.LX = maybeFangtieXList[lastIndex - 1];
                            reckRFInfo.RX = maybeFangtieXList[lastIndex];
                            maybeFangtieXList.RemoveAt(lastIndex);
                            maybeFangtieXList.RemoveAt(lastIndex - 1);
                        }
                        reckRFInfo.Width = Math.Round((double)reckRFInfo.RX - (double)reckRFInfo.LX, 0);
                        //Line Sort Out C Fangtie
                        if(maybeFangtieXList.Count > 0)
                        {
                            if(maybeFangtieXList.Count == 2)
                            {
                                reckCFInfo.fangtieAppType = FangtieAppType.Stand;
                                reckCFInfo.LX = maybeFangtieXList[0];
                                reckCFInfo.RX = maybeFangtieXList[1];
                                reckCFInfo.Width = Math.Round((double)reckCFInfo.RX - (double)reckCFInfo.LX, 0);
                            }
                        }
                    }                    
                }

                FangtieShareData.FLXInfo.CustomerX = (double)reckLFInfo.RX;
                FangtieShareData.FRXInfo.CustomerX = (double)reckRFInfo.LX;

            }

            //无方铁 需要自动补齐方铁两侧范围
            if (LastFIndex == -1)
            {
                double bWidth = MoldBaseShare.Width;
                //为了区分导柱 / 拉杆的识别区域
                double SFWidth = CU.FangtieSPWidth(MoldBaseShare.Width);
                double HalfW = bWidth / 2;
                double CPX = modlHInfo.CustomerPoint.X;
                double LFX = CPX - HalfW + SFWidth;
                double RFX = CPX + HalfW - SFWidth;
                FangtieShareData.HasLRF = false;
                FangtieShareData.NOFLXInfo.CustomerX = LFX;
                FangtieShareData.NOFRXInfo.CustomerX = RFX;
                FangtieShareData.NOFLXInfo.F = true;
                FangtieShareData.NOFRXInfo.F = true;
            }

            //设置方铁板的全量信息
            //起码判断出LR方铁 才设置数据
            Boolean reckF1 = reckLFInfo.fangtieAppType != FangtieAppType.None;
            Boolean reckF2 = reckRFInfo.fangtieAppType != FangtieAppType.None;
            Boolean reckF3 = reckCFInfo.fangtieAppType != FangtieAppType.None;
            if (LastFIndex != -1 && reckF1 && reckF2 && reckLFInfo.LX != null && reckLFInfo.RX != null)
            {
                //左方铁
                double FLCenterX = ((double)reckLFInfo.LX + (double)reckLFInfo.RX) / 2;
                AssemblyShareData.ASectionList[LastFIndex].Num = 1;
                AssemblyShareData.ASectionList[LastFIndex].PlateWidth = (double)reckLFInfo.Width;
                AssemblyShareData.ASectionList[LastFIndex].extraFInfo.RelFBCPoint.X = FLCenterX;
                AssemblyShareData.ASectionList[LastFIndex].extraFInfo.fPosType = FPosType.L;
                AssemblyShareData.ASectionList[LastFIndex].extraFInfo.FFlag = true;
                AssemblyShareData.ASectionList[LastFIndex].withaBoardPosType = UnloadMoldPosType.aBoardDown;
                //+一条右方铁记录
                BoardSectionItem fangtie2Info = (BoardSectionItem)ConvertUtils.DeepCopyObject(AssemblyShareData.ASectionList[LastFIndex]);
                double FRCenterX = ((double)reckRFInfo.LX + (double)reckRFInfo.RX) / 2;
                fangtie2Info.PlateWidth = (double)reckRFInfo.Width;
                fangtie2Info.extraFInfo.RelFBCPoint.X = FRCenterX;
                fangtie2Info.extraFInfo.fPosType = FPosType.R;
                fangtie2Info.extraFInfo.FFlag = true;
                fangtie2Info.withaBoardPosType = UnloadMoldPosType.aBoardDown;
                AssemblyShareData.ASectionList.Insert(LastFIndex + 1, fangtie2Info);
                if (reckF3)
                {
                    //+一条中间方铁记录
                    BoardSectionItem fangtie3Info = (BoardSectionItem)ConvertUtils.DeepCopyObject(AssemblyShareData.ASectionList[LastFIndex]);
                    double FCCenterX = ((double)reckCFInfo.LX + (double)reckCFInfo.RX) / 2;
                    fangtie3Info.PlateWidth = (double)reckCFInfo.Width;
                    fangtie3Info.extraFInfo.RelFBCPoint.X = FCCenterX;
                    fangtie3Info.extraFInfo.fPosType = FPosType.C;
                    fangtie3Info.extraFInfo.FFlag = true;
                    fangtie3Info.withaBoardPosType = UnloadMoldPosType.aBoardDown;
                    AssemblyShareData.ASectionList.Insert(LastFIndex + 2, fangtie3Info);
                }
            }
        }

        public static void SetEPFPBoardWidth(List<MixedCAD_Line> TVList, List<MixedCAD_Circle> TVCirList)
        {
            List<BoardSectionItem> targetBList = AssemblyShareData.ASectionList;
            int epfpIndex = targetBList.FindIndex(item => item.BoardCode.Equals("epBoard") || item.BoardCode.Equals("fpBoard"));
            if (epfpIndex != -1)
            {
                List<MixedCAD_Line> operTVList = (List<MixedCAD_Line>)ConvertUtils.DeepCopyObject(TVList);
                if (operTVList.Count > 0)
                {
                    for (int i = 0; i < operTVList.Count; i++)
                    {
                        MixedCAD_Line temp = operTVList[i];
                        if (temp.SPChamferFlag)
                            temp.Length += Math.Abs(temp.SCLine.StartPoint.CustomerPoint.X - temp.SCLine.EndPoint.CustomerPoint.X);
                        if (temp.EPChamferFlag)
                            temp.Length += Math.Abs(temp.ECLine.StartPoint.CustomerPoint.X - temp.ECLine.EndPoint.CustomerPoint.X);
                    }
                }
                if (MoldBaseShare.tvInfo.canCalF)
                {
                    double epfpMaxY = MoldBaseShare.tvInfo.TVMaxY;
                    double epfpMinY = MoldBaseShare.tvInfo.TVMinY;
                    double areaMaxY = MoldBaseShare.tvInfo.TVMaxY;
                    double areaMinY = MoldBaseShare.tvInfo.TVMinY;
                    List<double> CYList = TVCirList.Select(item => item.CenterPoint.CustomerPoint.Y).ToList();
                    if (CYList.Count > 0)
                    {
                        double CMaxY = CYList.Max();
                        double CMinY = CYList.Min();
                        double FWidth = Math.Round((double)FangtieShareData.FRXInfo.SplitX - (double)FangtieShareData.FLXInfo.SplitX, 1);
                        List<MixedCAD_Line> targeLList = operTVList.FindAll(item => item.Length - 0.5 <= FWidth && FWidth <= item.Length + 0.5);
                        if (targeLList.Count > 0)
                        {
                            List<MixedCAD_Line> BigYLList = targeLList.FindAll(item => CMaxY < item.StartPoint.CustomerPoint.Y 
                            && item.StartPoint.CustomerPoint.Y < areaMaxY);
                            List<MixedCAD_Line> SmallYLList = targeLList.FindAll(item => areaMinY < item.StartPoint.CustomerPoint.Y 
                            && item.StartPoint.CustomerPoint.Y < CMinY);
                            if (BigYLList.Count > 0)
                                epfpMaxY = BigYLList.Select(item => item.StartPoint.CustomerPoint.Y).ToList().Max();
                            if (SmallYLList.Count > 0)
                                epfpMinY = SmallYLList.Select(item => item.StartPoint.CustomerPoint.Y).ToList().Min();
                        }
                    }
                    double targetL = Math.Round(epfpMaxY - epfpMinY, 2);
                    for (int i = 0; i < targetBList.Count; i++)
                    {
                        Boolean F = targetBList[i].BoardCode.Equals("epBoard") || targetBList[i].BoardCode.Equals("fpBoard");
                        if (F)
                            targetBList[i].PlateLength = targetL;
                    }
                }
            }
        }

        public static void SetBoardSteel(List<MixedCAD_Text> TextList)
        {
            if (TextList.Count > 0)
                TextList = TextList.OrderByDescending(item => item.PositionPoint.CustomerPoint.Y).ToList();
            if (TextList.Count > 0 && AssemblyShareData.ASectionList.Count > 0)
            {
                for (int i = 0; i < TextList.Count; i++)
                {
                    for (int j = 0; j < AssemblyShareData.ASectionList.Count; j++)
                    {
                        double WordY = TextList[i].PositionPoint.CustomerPoint.Y;
                        double WordX = TextList[i].PositionPoint.CustomerPoint.X;
                        double TY = AssemblyShareData.ASectionList[j].OverheadLine.StartPoint.CustomerPoint.Y;
                        double BY = AssemblyShareData.ASectionList[j].BottomLine.StartPoint.CustomerPoint.Y;
                        double LX = AssemblyShareData.ASectionList[j].BottomLine.StartPoint.CustomerPoint.X;
                        double RX = AssemblyShareData.ASectionList[j].BottomLine.EndPoint.CustomerPoint.X;
                        Boolean F1 = BY < WordY && WordY < TY;
                        Boolean F2 = LX < WordX && WordX < RX;
                        if (F1 && F2)
                        {
                            if (!AssemblyShareData.ASectionList[j].Steel.MatchFlag)
                            {
                                double SSize = AssemblyShareData.ASectionList[j].Steel.SteelStrSize;
                                List<string> containStrList = new List<string>();
                                string comformCentet = ComputedUtils.CompareSteel(TextList[i].Centent);
                                if (comformCentet != null)
                                {
                                    AssemblyShareData.ASectionList[j].Steel.SteelName = comformCentet;
                                    AssemblyShareData.ASectionList[j].Steel.MatchFlag = true;
                                }
                            }
                        }

                    }
                }

            }
        }

        public static void SetHanging(List<AralinPrimions> LaringList)
        {
            try
            {
                List<BoardSectionItem> BoardList = AssemblyShareData.ASectionList;
                //扫描客户来图 板是否有吊令
                for (int i = 0; i < BoardList.Count; i++)
                {
                    CAD_Point RefPoint = new CAD_Point();
                    Boolean F = BoardList[i].BoardCode.Equals("fangtie");
                    if (F)
                        RefPoint = BoardList[i].extraFInfo.RelFBCPoint;
                    else
                        RefPoint = BoardList[i].CusBCPoint;

                    double TY = BoardList[i].OverheadLine.StartPoint.CustomerPoint.Y;
                    double BY = BoardList[i].BottomLine.StartPoint.CustomerPoint.Y;
                    double LX = RefPoint.X - BoardList[i].PlateWidth / 2;
                    double RX = RefPoint.X + BoardList[i].PlateWidth / 2;

                    for (int j = 0; j < LaringList.Count; j++)
                    {
                        double? LarX = LaringList[j].CenterX;
                        double? LarY = LaringList[j].CenterY;
                        if (LarX != null && LarY != null)
                        {
                            if (BY < LarY && LarY < TY && LX < LarX && LarX < RX)
                            {
                                Boolean DoubleCirF = LaringList[j].CircleList.Count == 2;
                                Boolean SimpleCirF = LaringList[j].CircleList.Count == 1;
                                Boolean SCirAndS = LaringList[j].IsContainArcFlag;
                                if (DoubleCirF)
                                {
                                    LaringList[j].CircleList = LaringList[j].CircleList.OrderBy(item => item.Diameter).ToList();
                                    double SLX = Math.Round(RefPoint.X - 2, 0);
                                    double SRX = Math.Round(RefPoint.X + 2, 0);
                                    if (SLX <= Math.Round((double)LarX, 0) && Math.Round((double)LarX, 0) <= SRX)
                                    {
                                        if (JudgeDCHanging(LaringList[j].CircleList))
                                        {
                                            BoardList[i].Hanging.HangingParam.CenterPoint.X = (double)LarX;
                                            BoardList[i].Hanging.HangingParam.CenterPoint.Y = (double)LarY;
                                            BoardList[i].Hanging.HangingParam.DicX = Math.Round((double)LarX - RefPoint.X, 0);
                                            BoardList[i].Hanging.HangingParam.DicY = Math.Round((double)LarY - RefPoint.Y, 0);
                                            double CustomDim = Math.Round(LaringList[j].CircleList[1].Diameter, 1);
                                            BoardList[i].Hanging.HangingParam.Dim = CustomDim;
                                            BoardList[i].Hanging.Num += 2;
                                            //Compare DB Data
                                            double AutoCDim = CU.AutoSetPulllingParam(BoardList[i].BoardCode, BoardList[i].PlateThick, "ALL");
                                            if (AutoCDim - 0.1 <= CustomDim && CustomDim <= AutoCDim + 0.1)
                                                BoardList[i].Hanging.DimStandardType = StandardType.Standard;
                                            else
                                                BoardList[i].Hanging.DimStandardType = StandardType.NonStandard;
                                            //判断位置是否标准
                                            double SBY = Math.Round(RefPoint.Y - 2, 0);
                                            double STY = Math.Round(RefPoint.Y + 2, 0);
                                            Boolean XF = SLX <= Math.Round((double)LarX, 0) && Math.Round((double)LarX, 0) <= SRX;
                                            Boolean YF = SBY <= Math.Round((double)LarY, 0) && Math.Round((double)LarY, 0) <= STY;
                                            if (XF && YF)
                                                BoardList[i].Hanging.PosstandardType = StandardType.Standard;
                                            else
                                                BoardList[i].Hanging.PosstandardType = StandardType.NonStandard;
                                            //位置 Dim 都标准 才算标准
                                            if (BoardList[i].Hanging.PosstandardType == StandardType.Standard &&
                                                BoardList[i].Hanging.DimStandardType == StandardType.Standard)
                                                BoardList[i].Hanging.standardType = StandardType.Standard;
                                            else
                                                BoardList[i].Hanging.standardType = StandardType.NonStandard;

                                            BoardList[i].Hanging.BluePrintHHFlag = true;
                                        }
                                        //位置正确 但是大小不符合标准
                                        else
                                        {
                                            double CustomDim = Math.Round(LaringList[j].CircleList[1].Diameter, 1);
                                            BoardList[i].Hanging.HangingParam.Dim = CustomDim;
                                            BoardList[i].Hanging.Num += 2;
                                            BoardList[i].Hanging.PosstandardType = StandardType.Standard;
                                            BoardList[i].Hanging.DimStandardType = StandardType.NonStandard;
                                            BoardList[i].Hanging.standardType = StandardType.NonStandard;
                                            BoardList[i].Hanging.BluePrintHHFlag = true;
                                        }
                                    }
                                }

                                if (SimpleCirF && !SCirAndS)
                                {
                                    double SLX = Math.Round(RefPoint.X - 2, 0);
                                    double SRX = Math.Round(RefPoint.X + 2, 0);
                                    //Pos 
                                    if (SLX <= Math.Round((double)LarX, 0) && Math.Round((double)LarX, 0) <= SRX)
                                    {
                                        //Size 
                                        if (JudgeSCHanging(BoardList[i].BoardCode, LaringList[j].CircleList[0]))
                                        {
                                            BoardList[i].Hanging.HangingParam.CenterPoint.X = (double)LarX;
                                            BoardList[i].Hanging.HangingParam.CenterPoint.Y = (double)LarY;
                                            BoardList[i].Hanging.HangingParam.DicX = Math.Round((double)LarX - RefPoint.X, 0);
                                            BoardList[i].Hanging.HangingParam.DicY = Math.Round((double)LarY - RefPoint.Y, 0);
                                            //查看Y坐标
                                            double SBY = Math.Round(RefPoint.Y - 2, 0);
                                            double STY = Math.Round(RefPoint.Y + 2, 0);
                                            Boolean YF = SBY <= Math.Round((double)LarY, 0) && Math.Round((double)LarY, 0) <= STY;
                                            if (YF)
                                                BoardList[i].Hanging.PosstandardType = StandardType.Standard;
                                            else
                                                BoardList[i].Hanging.PosstandardType = StandardType.NonStandard;
                                            double CustomDim = Math.Round(LaringList[j].CircleList[0].Diameter, 1);
                                            BoardList[i].Hanging.HangingParam.Dim = CustomDim;
                                            BoardList[i].Hanging.Num += 2;
                                            double AutoCDim = CU.AutoSetPulllingParam(BoardList[i].BoardCode, BoardList[i].PlateThick, "ALL");
                                            if (AutoCDim - 0.1 <= CustomDim && CustomDim <= AutoCDim + 0.1)
                                                BoardList[i].Hanging.DimStandardType = StandardType.Standard;
                                            else
                                                BoardList[i].Hanging.DimStandardType = StandardType.NonStandard;
                                            //位置 Dim 都标准 才算标准
                                            if (BoardList[i].Hanging.PosstandardType == StandardType.Standard &&
                                                BoardList[i].Hanging.DimStandardType == StandardType.Standard)
                                                BoardList[i].Hanging.standardType = StandardType.Standard;
                                            else
                                                BoardList[i].Hanging.standardType = StandardType.NonStandard;
                                            BoardList[i].Hanging.BluePrintHHFlag = true;
                                        }
                                        //位置正确 但是大小不符合标准
                                        else
                                        {
                                            double CustomDim = Math.Round(LaringList[j].CircleList[0].Diameter, 1);
                                            BoardList[i].Hanging.HangingParam.Dim = CustomDim;
                                            BoardList[i].Hanging.Num += 2;
                                            BoardList[i].Hanging.PosstandardType = StandardType.Standard;
                                            BoardList[i].Hanging.DimStandardType = StandardType.NonStandard;
                                            BoardList[i].Hanging.standardType = StandardType.NonStandard;
                                            BoardList[i].Hanging.BluePrintHHFlag = true;
                                        }
                                    }
                                }

                                //单圆&单圆弧
                                if (SimpleCirF && SCirAndS)
                                {
                                    double SLX = Math.Round(RefPoint.X - 2, 0);
                                    double SRX = Math.Round(RefPoint.X + 2, 0);
                                    //判断位置
                                    if (SLX <= Math.Round((double)LarX, 0) && Math.Round((double)LarX, 0) <= SRX)
                                    {
                                        //大小符合吊令规格
                                        if (JudgeSCSAHanging(LaringList[j].CircleList[0], LaringList[j].OutSideArc))
                                        {
                                            BoardList[i].Hanging.HangingParam.CenterPoint.X = (double)LarX;
                                            BoardList[i].Hanging.HangingParam.CenterPoint.Y = (double)LarY;
                                            BoardList[i].Hanging.HangingParam.DicX = Math.Round((double)LarX - RefPoint.X, 0);
                                            BoardList[i].Hanging.HangingParam.DicY = Math.Round((double)LarY - RefPoint.Y, 0);
                                            double CustomDim = LaringList[j].OutSideArc.Radius * 2;
                                            BoardList[i].Hanging.HangingParam.Dim = Math.Round(CustomDim, 1);
                                            BoardList[i].Hanging.Num += 2;
                                            double AutoCDim = CU.AutoSetPulllingParam(BoardList[i].BoardCode, BoardList[i].PlateThick, "ALL");
                                            if (AutoCDim - 0.1 <= CustomDim && CustomDim <= AutoCDim + 0.1)
                                                BoardList[i].Hanging.DimStandardType = StandardType.Standard;
                                            else
                                                BoardList[i].Hanging.DimStandardType = StandardType.NonStandard;
                                            //判断位置是否标准
                                            double SBY = Math.Round(RefPoint.Y - 2, 0);
                                            double STY = Math.Round(RefPoint.Y + 2, 0);
                                            Boolean XF = SLX <= Math.Round((double)LarX, 0) && Math.Round((double)LarX, 0) <= SRX;
                                            Boolean YF = SBY <= Math.Round((double)LarY, 0) && Math.Round((double)LarY, 0) <= STY;
                                            if (XF && YF)
                                                BoardList[i].Hanging.PosstandardType = StandardType.Standard;
                                            else
                                                BoardList[i].Hanging.PosstandardType = StandardType.NonStandard;
                                            //位置 Dim 都标准 才算标准
                                            if (BoardList[i].Hanging.PosstandardType == StandardType.Standard &&
                                                BoardList[i].Hanging.DimStandardType == StandardType.Standard)
                                                BoardList[i].Hanging.standardType = StandardType.Standard;
                                            else
                                                BoardList[i].Hanging.standardType = StandardType.NonStandard;

                                            BoardList[i].Hanging.BluePrintHHFlag = true;
                                        }
                                        else
                                        {
                                            double CustomDim = LaringList[j].OutSideArc.Radius * 2;
                                            BoardList[i].Hanging.HangingParam.Dim = Math.Round(CustomDim, 1);
                                            BoardList[i].Hanging.Num += 2;
                                            BoardList[i].Hanging.PosstandardType = StandardType.Standard;
                                            BoardList[i].Hanging.DimStandardType = StandardType.NonStandard;
                                            BoardList[i].Hanging.standardType = StandardType.NonStandard;
                                            BoardList[i].Hanging.BluePrintHHFlag = true;
                                        }
                                    }
                                }

                            }
                        }
                    }
                }

                //单独处理关于方铁的吊令逻辑(LR方铁只要有一侧画了就表示两侧都有 C方铁单独)
                Boolean ExitsF = BoardList.FindIndex(item => item.BoardCode.Equals("fangtie")) != -1;
                if (ExitsF)
                {
                    int LFIndex = BoardList.FindIndex(item => item.extraFInfo.fPosType == FPosType.L);
                    int RFIndex = BoardList.FindIndex(item => item.extraFInfo.fPosType == FPosType.R);
                    int CFIndex = BoardList.FindIndex(item => item.extraFInfo.fPosType == FPosType.C);

                    if (LFIndex != -1 && RFIndex != -1)
                    {
                        double LFDim = BoardList[LFIndex].Hanging.HangingParam.Dim;
                        double RFDim = BoardList[RFIndex].Hanging.HangingParam.Dim;
                        Boolean F1 = LFDim != 0;
                        Boolean F2 = RFDim != 0;
                        Boolean F3 = LFDim != RFDim;
                        if (F1 && !F2 && F3)
                        {
                            BoardList[RFIndex].Hanging.HangingParam.Dim = BoardList[LFIndex].Hanging.HangingParam.Dim;
                            BoardList[RFIndex].Hanging.Num = BoardList[LFIndex].Hanging.Num;
                        }
                        if (!F1 && F2 && F3)
                        {
                            BoardList[LFIndex].Hanging.HangingParam.Dim = BoardList[RFIndex].Hanging.HangingParam.Dim;
                            BoardList[LFIndex].Hanging.Num = BoardList[RFIndex].Hanging.Num;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string errorStr = ex.ToString();
                throw;
            }

        }

        //判断 双圆 吊令 内径 直径 是否标准
        public static Boolean JudgeDCHanging( List<MixedCAD_Circle> ConnCircleItem)
        {
            double InDim = ConnCircleItem[0].Diameter;
            double OutDim = ConnCircleItem[1].Diameter;
            //吊令标准参数
            List <StandardScrew> ScrewList = ParamsConfigData.StandardScrewList;
            for(int i = 0; i < ScrewList.Count; i++)
            {
                double CInDim = Convert.ToDouble(ScrewList[i].BaseDimension);
                double CDim = Convert.ToDouble(ScrewList[i].Dimension);
                Boolean F1 = CDim - 0.02 <= OutDim && OutDim <= CDim + 0.02;
                //放大
                Boolean F2 = CInDim - 0.2 <= InDim && InDim <= CInDim + 0.2;
                if (F1 && F2)
                    return true;
            }
            return false;
        }

        //判断 单圆&单圆弧 吊令 直径 是否标准
        public static Boolean JudgeSCSAHanging(MixedCAD_Circle circle, MixedCAD_Arc arc)
        {
            double InDim = circle.Diameter;
            double OutDim = arc.Radius * 2;
            //吊令标准参数
            List<StandardScrew> ScrewList = ParamsConfigData.StandardScrewList;
            for (int i = 0; i < ScrewList.Count; i++)
            {
                double CInDim = Convert.ToDouble(ScrewList[i].BaseDimension);
                double CDim = Convert.ToDouble(ScrewList[i].Dimension);
                Boolean F1 = CDim - 0.02 <= OutDim && OutDim <= CDim + 0.02;
                Boolean F2 = CInDim - 0.2 <= InDim && InDim <= CInDim + 0.2;
                if (F1 && F2)
                    return true;
            }
            return false;
        }

        //判断 单圆 吊令是否符合标准 板 Dim圆
        public static Boolean JudgeSCHanging(string BoardCode, MixedCAD_Circle DimCirItem)
        {
            double Dim = DimCirItem.Diameter;
            PullingDimItem ScopeDim = StandardShareScopeItemParam.PullingDimParam;
            if (BoardCode.Equals("aBoard") || BoardCode.Equals("bBoard"))
                return ScopeDim.ABDimList.FindIndex(item => item - 0.02 <= Dim && Dim <= item + 0.02) != -1;
            if (BoardCode.Equals("cpBoard"))
                return ScopeDim.skmbDimList.FindIndex(item => item - 0.02 <= Dim && Dim <= item + 0.02) != -1;
            if (BoardCode.Equals("spBoard"))
                return ScopeDim.tuobanDimList.FindIndex(item => item - 0.02 <= Dim && Dim <= item + 0.02) != -1;
            if (BoardCode.Equals("bpBoard"))
                return ScopeDim.dbmbDimList.FindIndex(item => item - 0.02 <= Dim && Dim <= item + 0.02) != -1;
            if (BoardCode.Equals("stBoard") || BoardCode.Equals("rspBoard") || BoardCode.Equals("rBoard"))
                return ScopeDim.tuibanDimList.FindIndex(item => item - 0.02 <= Dim && Dim <= item + 0.02) != -1;
            if (BoardCode.Equals("fangtie"))
                return ScopeDim.fangtieDimList.FindIndex(item => item - 0.02 <= Dim && Dim <= item + 0.02) != -1;
            if (BoardCode.Equals("fpBoard") || BoardCode.Equals("epBoard"))
                return ScopeDim.zhenbanDimList.FindIndex(item => item - 0.02 <= Dim && Dim <= item + 0.02) != -1;
            return false;
        }

        //判断两条折线是否形成尖(尖是两条相连的斜线 等腰梯形)
        public static double? JudgeTwoObliqueTooth(MixedCAD_Line line1, MixedCAD_Line line2)
        {
            double Conditions1 = CU.JudgeTwoLineConnLEqual(line1, line2);
            Boolean Conditions2 = CU.JudgeTwoLineSlopeEqual(line1, line2);
            double line1MinY = line1.StartPoint.TransSplitPoint.Y < line1.EndPoint.TransSplitPoint.Y ? line1.StartPoint.TransSplitPoint.Y : line1.EndPoint.TransSplitPoint.Y;
            double line1MaxY = line1.StartPoint.TransSplitPoint.Y > line1.EndPoint.TransSplitPoint.Y ? line1.StartPoint.TransSplitPoint.Y : line1.EndPoint.TransSplitPoint.Y;
            double line2MinY = line2.StartPoint.TransSplitPoint.Y < line2.EndPoint.TransSplitPoint.Y ? line2.StartPoint.TransSplitPoint.Y : line2.EndPoint.TransSplitPoint.Y;
            double line2MaxY = line2.StartPoint.TransSplitPoint.Y > line2.EndPoint.TransSplitPoint.Y ? line2.StartPoint.TransSplitPoint.Y : line2.EndPoint.TransSplitPoint.Y;
            Boolean Y1F = Math.Round(line1MinY, 1) == Math.Round(line2MinY, 1);
            Boolean Y2F = Math.Round(line1MaxY, 1) == Math.Round(line2MaxY, 1);
            Boolean Conditions3 = Y1F && Y2F;
            if (Conditions2 && Conditions3 && Conditions1 != -1)
                return Conditions1;
            return null;
        }

        //推算 投影 客图 中心点
        public static void ImTVRefCustomerCenterCoor(List<MixedCAD_Line> TVNoCLList)
        {

            MixedCAD_Line tagetXTypeLine = new MixedCAD_Line();
            MixedCAD_Line tagetYTypeLine = new MixedCAD_Line();
            List<MixedCAD_Line> XList = TVNoCLList.FindAll(item => item.LineType == CADLineType.XDirLine).ToList();
            List<MixedCAD_Line> YList = TVNoCLList.FindAll(item => item.LineType == CADLineType.YDirLine).ToList();
            if (XList.Count > 0)
            {
                double targetXL = XList.Select(item => item.Length).ToList().Max();
                targetXL = Math.Round(targetXL, 1);
                List<MixedCAD_Line> targetXList = XList.FindAll(item => Math.Round(item.Length,1) == targetXL).ToList();
                if (targetXList.Count > 0)
                {
                    double maxY = targetXList.Max(item => item.StartPoint.CustomerPoint.Y);
                    double minY = targetXList.Min(item => item.StartPoint.CustomerPoint.Y);
                    double CenterY = (maxY + minY) / 2;
                    WholeTopViewData.ModlCenterInfo.TransF = true;
                    WholeTopViewData.ModlCenterInfo.CustomerPoint.Y = CenterY;
                }
            }
            if (YList.Count > 0)
            {
                double targetYL = YList.Select(item => item.Length).ToList().Max();
                targetYL = Math.Round(targetYL, 1);
                List<MixedCAD_Line> targetYList = YList.FindAll(item => Math.Round(item.Length,1) == targetYL).ToList();
                if (targetYList.Count > 0)
                {
                    double maxX = targetYList.Max(item => item.StartPoint.CustomerPoint.X);
                    double minX = targetYList.Min(item => item.StartPoint.CustomerPoint.X);
                    double CenterX = (maxX + minX) / 2;
                    WholeTopViewData.ModlCenterInfo.TransF = true;
                    WholeTopViewData.ModlCenterInfo.CustomerPoint.X = CenterX;
                }
            }

        }

        //在判断出拉杆有介子的情况下 补充介子规格
        public static SingleItem RepMesonSpe(double spItemDim)
        {
            SingleItem misItem = new SingleItem();
            misItem.ItemNameType = DItemNameType.Meson;
            int sIndex = ParamsConfigData.StandardSPScrewMesonList.FindIndex(item => item.spDim == spItemDim);
            if(sIndex != -1)
            {
                StandardSPScrewMeson targetItem = ParamsConfigData.StandardSPScrewMesonList[sIndex];
                misItem.Dim = targetItem.spMesonTD;
                misItem.RealH = targetItem.spMesonTH;
                misItem.TheoryH = targetItem.spMesonTH;
            }
            return misItem;
        }

        //在判断出拉杆有介子的情况下 补充 水介螺丝规格
        public static SingleItem RepMesonScrewSpe(double spItemDim)
        {
            SingleItem misScrewItem = new SingleItem();
            misScrewItem.ItemNameType = DItemNameType.MesonScrew;
            int sIndex = ParamsConfigData.StandardSPScrewMesonList.FindIndex(item => item.spDim == spItemDim);
            if (sIndex != -1)
            {
                StandardSPScrewMeson targetItem = ParamsConfigData.StandardSPScrewMesonList[sIndex];
                misScrewItem.Dim = targetItem.MesonScrewDim;
                misScrewItem.RealH = targetItem.MesonScrewL;
                misScrewItem.TheoryScrewH = targetItem.MesonScrewL;
            }
            return misScrewItem;
        }
    
    }
}
